GoodsAgentForm.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. namespace app\modules\alliance\models;
  3. use app\constants\OptionSetting;
  4. use app\models\Admin;
  5. use app\models\AgentBind;
  6. use app\models\AgentGoodsBindGoods;
  7. use app\models\AgentGoodsInstallLog;
  8. use app\models\District;
  9. use app\models\Goods;
  10. use app\models\Order;
  11. use app\models\OrderDetail;
  12. use app\models\OrderTransit;
  13. use app\models\PurchaseOrder;
  14. use app\models\PurchaseOrderDetail;
  15. use app\models\SaasUser;
  16. use app\models\Store;
  17. use app\models\Supplier;
  18. use app\modules\admin\models\PlatformForm;
  19. use yii\base\Model;
  20. class GoodsAgentForm extends Model
  21. {
  22. public $id;
  23. public $admin_id;
  24. public $cloud_goods_id;
  25. public $goods_name;
  26. public $page;
  27. public $limit;
  28. public $order_no;
  29. public function rules() {
  30. return [
  31. [['goods_name', 'order_no'], 'string'],
  32. [['admin_id', 'cloud_goods_id', 'page', 'limit', 'id'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * 获取产品代理首页
  37. */
  38. public function getInfo() {
  39. try {
  40. $saasUser = get_saas_user();
  41. $admin = get_admin();
  42. $saas_name = $saasUser->name;
  43. //店铺管理员名称
  44. $title = [
  45. 'user_name' => $saasUser->name,
  46. 'mobile' => $saasUser->mobile,
  47. 'avatar' => $saasUser->avatar
  48. ];
  49. //获取昨日凌晨时间
  50. $yet = strtotime(date('Y-m-d')) - (60 * 60 * 24);
  51. //获取今日凌晨时间
  52. $td = strtotime(date('Y-m-d'));
  53. //获取明日凌晨时间
  54. // $tot = strtotime(date('Y-m-d')) + (60 * 60 * 24);
  55. //
  56. // $timestamp = time();
  57. //代理产品数量
  58. $agent_goods_query = AgentGoodsBindGoods::find()->where(['goods_agent_admin_id' => $admin->id, 'is_delete' => 0]);
  59. //昨日代理产品数量
  60. $yet_agent_goods_query = clone $agent_goods_query;
  61. $yet_agent_goods_query->andWhere(['AND', ['>', 'created_at', $yet], ['<', 'created_at', $td]]);
  62. $yet_agent_goods_count = $yet_agent_goods_query->count();
  63. $agent_goods_count = $agent_goods_query->count();
  64. //订单数量
  65. $order_query = AgentGoodsInstallLog::find()->alias('ag')->leftJoin(['o' => Order::tableName()], 'ag.order_id = o.id')
  66. ->where(['ag.goods_agent_admin_id' => $admin->id])->groupBy('o.id');
  67. //昨日订单数量
  68. $yet_order_query = clone $order_query;
  69. $yet_order_query->andWhere(['AND', ['>', 'ag.created_at', $yet], ['<', 'ag.created_at', $td]]);
  70. $order_count = $order_query->count();
  71. $yet_order_count = $yet_order_query->count();
  72. //通知
  73. $order = AgentGoodsInstallLog::find()->where(['goods_agent_admin_id' => $admin->id, 'status' => 0])
  74. ->orderBy('created_at')->select('id, is_need_install')->asArray()->all();
  75. $arr = [];
  76. $i = 0;
  77. foreach($order as $item){
  78. $arr[$i]['id'] = $item['id'];
  79. if ($item['is_need_install']) {
  80. $arr[$i]['notice'] = '您有新的订单需要上门安装';
  81. } else {
  82. $arr[$i]['notice'] = '您有新的订单需要配送';
  83. }
  84. $i++;
  85. }
  86. $notice = $arr;
  87. return [
  88. 'code' => 0,
  89. 'msg' => "获取成功",
  90. 'data' => [
  91. 'notice' => $notice,
  92. 'title' => $title,
  93. 'total' => [
  94. 'order_num' => [//订单数
  95. 'order_count' => $order_count,
  96. 'yet_order_count' => $yet_order_count
  97. ],
  98. 'goods' => [//成交额
  99. 'money_count' => $agent_goods_count,
  100. 'yet_money_count' => $yet_agent_goods_count??0
  101. ]
  102. ]
  103. ]
  104. ];
  105. } catch (\Exception $e) {
  106. return [
  107. 'code' => 1,
  108. 'msg' => $e->getMessage()
  109. ];
  110. }
  111. }
  112. /**
  113. * 绑定商品
  114. */
  115. public function bindFrontAgentGoods() {
  116. try {
  117. $admin = get_admin();
  118. //获取商品
  119. $form = new PlatformForm();
  120. if (!$this->cloud_goods_id) {
  121. throw new \Exception('未选择产品');
  122. }
  123. $admin_id = $admin->id;
  124. $agent_bind = AgentBind::findOne(['admin_id' => $admin->id]);
  125. $parent_admin_id = $agent_bind->parent_admin_id;
  126. $result = $this->checkGoodsBind($parent_admin_id, $admin_id);
  127. if ($result['code'] === 0) {
  128. if (in_array($this->cloud_goods_id, $result['data'])) {
  129. throw new \Exception('该商品已经绑定其他产品代理');
  130. }
  131. } else {
  132. throw new \Exception($result['msg']);
  133. }
  134. $form->type = 1;
  135. $form->send_type = 3;
  136. $form->id = $this->cloud_goods_id;
  137. $result = $form->goodsList();
  138. if ($result['code'] !== 0 || empty($result['data']['list'])) {
  139. throw new \Exception('商品查询失败');
  140. }
  141. //绑定产品
  142. if (empty($admin_id)) {
  143. throw new \Exception('未选择产品代理');
  144. }
  145. $agent_goods_bind = AgentGoodsBindGoods::findOne(['goods_agent_admin_id' => $admin_id, 'is_delete' => 0, 'status' => [0, 1], 'cloud_goods_id' => $this->cloud_goods_id]);
  146. if (!$agent_goods_bind) {
  147. $agent_goods_bind = new AgentGoodsBindGoods();
  148. $agent_goods_bind->status = 0;
  149. }
  150. $agent_goods_bind->goods_agent_admin_id = $admin_id;
  151. $agent_goods_bind->cloud_goods_id = $this->cloud_goods_id;
  152. $agent_goods_bind->cloud_supplier_id = $result['data']['list'][0]['supplier_id'];
  153. if (!$agent_goods_bind->save()) {
  154. throw new \Exception(json_encode($agent_goods_bind->errors));
  155. }
  156. return [
  157. 'code' => 0,
  158. 'msg' => '绑定成功'
  159. ];
  160. } catch (\Exception $e) {
  161. return [
  162. 'code' => 1,
  163. 'msg' => $e->getMessage()
  164. ];
  165. }
  166. }
  167. /**
  168. * 获取未绑定的产品列表
  169. */
  170. public function frontAgentGoodsList() {
  171. try {
  172. $admin = get_admin();
  173. $goods_name = $this->goods_name;
  174. if ($admin->type !== 'goods_agent') {
  175. throw new \Exception('权限错误');
  176. }
  177. //获取商品
  178. $form = new PlatformForm();
  179. $form->page = $this->page;
  180. $form->limit = $this->limit;
  181. $form->send_type = 3;
  182. //商品名称
  183. if (!empty($goods_name)) {
  184. $form->name = $goods_name;
  185. }
  186. //供货商id
  187. if (!empty($supplier_id)) {
  188. $form->supplier_id = $supplier_id;
  189. }
  190. //分类
  191. // if (!empty($cat_id)) {
  192. // $form->cat_id = $cat_id;
  193. // }
  194. //最大金额
  195. if (!empty($min_money)) {
  196. $form->min_money = $min_money;
  197. }
  198. //最大金额
  199. if (!empty($max_money)) {
  200. $form->max_money = $max_money;
  201. }
  202. $agent_bind = AgentBind::findOne(['admin_id' => $admin->id]);
  203. $parent_admin_id = $agent_bind->parent_admin_id;
  204. //产品代理
  205. // $result = $this->getSupplier($parent_admin_id);
  206. //
  207. // if ($result['code'] === 0) {
  208. // if (!empty($supplier_id)) {
  209. // $supplier_id = array_intersect($result['data'], [$supplier_id]);
  210. // } else {
  211. // $supplier_id = $result['data'];
  212. // }
  213. //// $supplier_id = $result['data'];
  214. // } else {
  215. // throw new \Exception($result['msg']);
  216. // }
  217. //找到同级产品代理,检测某个商品是否已经被代理
  218. $result = $this->checkGoodsBind($parent_admin_id);
  219. if ($result['code'] === 0) {
  220. $filter_cloud_goods_id = $result['data'];
  221. } else {
  222. throw new \Exception($result['msg']);
  223. }
  224. //获取商品
  225. $form->type = 1;
  226. //剔除被代理的产品
  227. $form->filter_goods_id = implode(',', $filter_cloud_goods_id);
  228. return $form->goodsList();
  229. } catch (\Exception $e) {
  230. return [
  231. 'code' => 1,
  232. 'msg' => $e->getMessage()
  233. ];
  234. }
  235. }
  236. /**
  237. * 删除绑定商品
  238. */
  239. public function delBindFrontAgentGoods() {
  240. try {
  241. $id = $this->id;
  242. $agent_goods_bind_goods = AgentGoodsBindGoods::findOne(['id' => $id, 'is_delete' => 0]);
  243. if (!$agent_goods_bind_goods) {
  244. throw new \Exception('未查找到信息');
  245. }
  246. $agent_goods_bind_goods->is_delete = 1;
  247. if (!$agent_goods_bind_goods->save()) {
  248. throw new \Exception(json_encode($agent_goods_bind_goods->errors));
  249. }
  250. return [
  251. 'code' => 0,
  252. 'msg' => '删除成功'
  253. ];
  254. } catch (\Exception $e) {
  255. return [
  256. 'code' => 1,
  257. 'msg' => $e->getMessage()
  258. ];
  259. }
  260. }
  261. /**
  262. * 获取已经绑定产品列表
  263. */
  264. public function getBindGoodsList() {
  265. //查询条件 商品名称 代理名称 供货商
  266. try {
  267. $admin = get_admin();
  268. $goods_name = $this->goods_name;
  269. if ($admin->type !== 'goods_agent') {
  270. throw new \Exception('权限错误');
  271. }
  272. //获取当前的产品代理
  273. $goods_agent_admin_id = $admin->id;
  274. //查询绑定的商品信息
  275. $query = AgentGoodsBindGoods::find()->alias('agbg')
  276. ->where(['agbg.is_delete' => 0])
  277. ->leftJoin(['a' => Admin::tableName()], 'agbg.goods_agent_admin_id = a.id')
  278. ->leftJoin(['su' => SaasUser::tableName()], 'a.saas_user_id = su.id')
  279. ->select('agbg.id, agbg.cloud_goods_id, agbg.goods_agent_admin_id, a.saas_user_id, agbg.status, a.name user_name, su.avatar, agbg.cloud_supplier_id, agbg.status bind_status');//->asArray()->all();
  280. //搜索状态
  281. if ($goods_agent_admin_id) {
  282. $query->andWhere(['agbg.goods_agent_admin_id' => $goods_agent_admin_id]);
  283. }
  284. // if ($status != -1 && $status !== null) {
  285. // $query->andWhere(['agbg.status' => $status]);
  286. // }
  287. // //搜索代理名称
  288. // if ($admin_name) {
  289. // $query->andWhere(['LIKE', 'su.name', $admin_name]);
  290. // }
  291. //
  292. // //搜索供货商
  293. // if ($supplier_name) {
  294. // $supplier_id = Supplier::find()->where(['like', 'supplier_name', $supplier_name])->select('cloud_supplier_id')->column();
  295. // $query->andWhere(['agbg.cloud_supplier_id' => $supplier_id]);
  296. // }
  297. $list = $query->asArray()->all();
  298. // $pagination = pagination_make($query);
  299. // $list = $pagination['list'];
  300. if (!empty($list)) {
  301. $form = new PlatformForm();
  302. $form->type = 1;
  303. $goods_ids = array_column($list, 'cloud_goods_id');
  304. $goods_ids = implode(',', $goods_ids);
  305. // foreach ($pagination['list'] as &$goods) {
  306. // $saas_user = SaasUser::findOne($goods['saas_user_id']);
  307. // $goods['saas_user'] = [
  308. // 'name' => $saas_user->name,
  309. // 'avatar' => $saas_user->avatar,
  310. // ];
  311. $form->ids = $goods_ids;
  312. $form->limit = $this->limit;
  313. $form->page = $this->page;
  314. $form->send_type = 3;
  315. if ($goods_name) {
  316. $form->name = $goods_name;
  317. }
  318. $result = $form->goodsList();
  319. if ($result['code'] !== 0) {
  320. throw new \Exception($result['msg']);
  321. }
  322. foreach ($result['data']['list'] as &$goods) {
  323. foreach ($list as $value) {
  324. $value['bind_status'] *= 1;
  325. if ($value['cloud_supplier_id']) {
  326. $supplier = Supplier::findOne(['cloud_supplier_id' => $value['cloud_supplier_id']]);
  327. $value['supplier_name'] = $supplier->supplier_name;
  328. } else {
  329. $value['supplier_name'] = '-';
  330. }
  331. if ((int)$goods['id'] === (int)$value['cloud_goods_id']) {
  332. $goods = array_merge($goods, $value);
  333. }
  334. }
  335. }
  336. // $goods = array_merge($goods, $result['data']['list'][0]);
  337. // }
  338. return [
  339. 'code' => 0,
  340. 'msg' => '获取成功',
  341. 'data' => [
  342. 'list' => $result['data']['list'],
  343. 'pageNo' => $this->page,
  344. 'totalCount' => $result['data']['count'],
  345. ]
  346. ];
  347. } else {
  348. return [
  349. 'code' => 0,
  350. 'msg' => '获取成功',
  351. 'data' => [
  352. 'list' => [],
  353. 'pageNo' => 0,
  354. 'totalCount' => 0,
  355. ]
  356. ];
  357. }
  358. } catch (\Exception $e) {
  359. return [
  360. 'code' => 1,
  361. 'msg' => $e->getMessage()
  362. ];
  363. }
  364. }
  365. /**
  366. * 获取订单列表
  367. */
  368. public function getInstallLog() {
  369. try {
  370. // $status = $this->status;
  371. $order_no = $this->order_no;
  372. // $admin_name = $this->admin_name;
  373. // $store_name = $this->store_name;
  374. // $start_time = $this->start_time;
  375. // $end_time = $this->end_time;
  376. // $min_money = $this->min_money;
  377. // $max_money = $this->max_money;
  378. $admin = get_admin();
  379. $order_query = AgentGoodsInstallLog::find()->alias('agil')
  380. ->leftJoin(['a' => Admin::tableName()], 'agil.goods_agent_admin_id = a.id')
  381. ->where(['is_delete' => 0]);
  382. $order_query->andWhere(['goods_agent_admin_id' => $admin->id]);
  383. ;//->select('order_id')->column();
  384. // if ($status !== null && (int)$status !== -1) {
  385. // $order_query->andWhere(['agil.status' => $status]);
  386. // }
  387. // if ($admin_name) {
  388. // $order_query->andWhere(['LIKE', 'a.name', $admin_name]);
  389. // }
  390. $order_arr = $order_query->groupBy('order_id')->select('agil.order_id, agil.order_type')->column();
  391. $order_id = [0];
  392. $purchase_order_id = [0];
  393. if (!empty($order_arr)) {
  394. foreach ($order_arr as $install_order_item) {
  395. if (intval($install_order_item['order_type']) === AgentGoodsInstallLog::ORDER_TYPE_NORMAL) {
  396. array_push($order_id, $install_order_item['order_id']);
  397. }
  398. if (intval($install_order_item['order_type']) === AgentGoodsInstallLog::ORDER_TYPE_PURCHASE) {
  399. array_push($purchase_order_id, $install_order_item['order_id']);
  400. }
  401. }
  402. }
  403. $order_table_name = Order::tableName();
  404. $purchase_order_table_name = PurchaseOrder::tableName();
  405. $store_table_name = Store::tableName();
  406. $order_id = implode(',', $order_id);
  407. $purchase_order_id = implode(',', $purchase_order_id);
  408. $fields = " id, order_no, created_at, confirm_time, pay_price, `name`, mobile, address_data, store_id ";
  409. $order_type_normal = AgentGoodsInstallLog::ORDER_TYPE_NORMAL;
  410. $order_type_purchase = AgentGoodsInstallLog::ORDER_TYPE_PURCHASE;
  411. $sql = "SELECT o.* FROM (SELECT {$fields}, {$order_type_normal} AS order_type FROM {$order_table_name} WHERE id IN ({$order_id}) AND is_delete = 0 AND trade_status IN (0, 2, 3)
  412. UNION ALL SELECT {$fields}, {$order_type_purchase} AS order_type FROM {$purchase_order_table_name} WHERE id IN ({$purchase_order_id}) AND is_delete = 0 AND trade_status IN (0, 2, 3))
  413. AS o LEFT JOIN {$store_table_name} s ON o.store_id = s.id WHERE o.id > 0 ";
  414. if ($order_no) {
  415. $sql .= " AND o.order_no LIKE '%{$order_no}%'";
  416. }
  417. $pageNo = get_params('pageNo', get_params('page', 1));
  418. $pageSize = get_params('pageSize', \Yii::$app->params['pageSize']);
  419. $pageInitNum = ($pageNo - 1) * $pageSize;
  420. $count = \Yii::$app->db->createCommand($sql)->query()->count();
  421. $sql .= " ORDER BY created_at desc LIMIT {$pageSize} OFFSET {$pageInitNum}";
  422. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  423. foreach ($list as &$item) {
  424. $item['status'] = 1;
  425. $item['created_at'] = !empty($item['created_at']) ? date('Y-m-d H:i:s', $item['created_at']) : '-';
  426. $item['confirm_time'] = !empty($item['confirm_time']) ? date('Y-m-d H:i:s', $item['confirm_time']) : '-';
  427. $order_detail_table_name = $item['order_type'] ? PurchaseOrderDetail::tableName() : OrderDetail::tableName();
  428. $item['goods_list'] = AgentGoodsInstallLog::find()->alias('agil')->where(['agil.order_id' => $item['id'], 'agil.goods_agent_admin_id' => get_admin()->id])
  429. ->leftJoin(['od' => $order_detail_table_name], 'agil.order_detail_id = od.id')
  430. ->leftJoin(['a' => Admin::tableName()], 'agil.goods_agent_admin_id = a.id')
  431. ->select('od.goods_name, od.attr, od.pic, od.num, od.total_price, agil.status, agil.is_need_install, a.name admin_name')->asArray()->all();
  432. foreach ($item['goods_list'] as &$value) {
  433. $value['status'] *= 1;
  434. $value['is_need_install'] *= 1;
  435. $value['attr'] = json_decode($value['attr'], true);
  436. if ($value['status'] === 0) {
  437. $item['status'] = 0;
  438. }
  439. if ($value['is_need_install'] === 1) {
  440. if ($item['address_data']) {
  441. $address_data = json_decode($item['address_data'], true);
  442. $address_data = $address_data['province'] . $address_data['city'] . $address_data['district'] . $address_data['detail'] ;
  443. } else {
  444. $address_data = '';
  445. }
  446. $value['address'] = $address_data;
  447. $value['mobile'] = $item['mobile'];
  448. $value['name'] = $item['name'];
  449. } else {
  450. $store = Store::findOne($item['store_id']);
  451. $province_id = $store->province_id;
  452. $city_id = $store->city_id;
  453. $district_id = $store->district_id;
  454. $district = District::find()->where(['id' => [$province_id, $city_id, $district_id]])->select('name')->column();
  455. $district = implode('', $district);
  456. $value['address'] = $district . $store->address;
  457. $value['mobile'] = $store->contact_tel;
  458. $value['name'] = $store->name;
  459. }
  460. }
  461. }
  462. return [
  463. 'code' => 0,
  464. 'msg' => 'success',
  465. 'data' => [
  466. 'data' => $list,
  467. 'pageNo' => $pageNo,
  468. 'totalCount' => $count,
  469. ],
  470. ];
  471. } catch (\Exception $e) {
  472. return [
  473. 'code' => 1,
  474. 'msg' => $e->getMessage()
  475. ];
  476. }
  477. }
  478. /**
  479. * 点击送达
  480. */
  481. public function setInstallStatus($order_type = 0) {
  482. $t = \Yii::$app->db->beginTransaction();
  483. try {
  484. $id = $this->id;
  485. $agent_order_type = AgentGoodsInstallLog::ORDER_TYPE_NORMAL;
  486. if (intval($order_type) !== 0) {
  487. $agent_order_type = AgentGoodsInstallLog::ORDER_TYPE_PURCHASE;
  488. }
  489. $install_log = AgentGoodsInstallLog::find()->where(['order_id' => $id, 'status' => 0, 'order_type' => $agent_order_type])->asArray()->all();
  490. if (empty($install_log)) {
  491. throw new \Exception('未查找到数据');
  492. }
  493. $is_finish = true;
  494. foreach ($install_log as $value) {
  495. if ((int)$value['status'] !== 0) {
  496. throw new \Exception('订单已经送达');
  497. }
  498. $item = AgentGoodsInstallLog::findOne($value['id']);
  499. $item->status = 1;
  500. if (!$item->save()) {
  501. throw new \Exception(json_encode($item->errors));
  502. }
  503. if (!$item->is_need_install) {
  504. $is_finish = false;
  505. }
  506. }
  507. //如果不需要上门安装 则发货操作由商家完成
  508. //模拟供货商发货即可(转单)
  509. if (intval($order_type)) {
  510. $purchase_order = PurchaseOrder::findOne(['cloud_order_id' => $id, 'is_delete' => 0]);
  511. $cloud_supplier_id = $purchase_order->cloud_supplier_id;
  512. $cloud_order_id = $purchase_order->cloud_order_id;
  513. $goods_url = "/cloud/supplier/supplierOrderSend";
  514. } else {
  515. $order_transit = OrderTransit::findOne(['order_id' => $id, 'is_delete' => 0]);
  516. $cloud_supplier_id = $order_transit->cloud_supplier_id;
  517. $cloud_order_id = $order_transit->cloud_order_id;
  518. $goods_url = "/cloud/supplier/supplierPurchaseSend";
  519. }
  520. $param = [
  521. 'order_ids' => (string)$cloud_order_id,
  522. 'access_token' => get_supplier_token($cloud_supplier_id),
  523. 'express_name' => '',
  524. 'express_no' => '',
  525. 'send_type' => 3,
  526. 'seller_desc' => '',
  527. ];
  528. //请求接口
  529. $domain = (new OptionSetting)->getCloudDomainName();
  530. $goodsInfo = cloud_post($domain . $goods_url, $param);
  531. $goodsInfo = json_decode($goodsInfo, true);
  532. if ((int)$goodsInfo['code'] !== 0) {
  533. throw new \Exception($goodsInfo['msg']);
  534. }
  535. $t->commit();
  536. return [
  537. 'code' => 0,
  538. 'msg' => '操作成功'
  539. ];
  540. } catch (\Exception $e) {
  541. $t->rollBack();
  542. return [
  543. 'code' => 1,
  544. 'msg' => $e->getMessage()
  545. ];
  546. }
  547. }
  548. /**
  549. * 找到同级产品代理,检测某个商品是否已经被代理并剔除
  550. */
  551. public function checkGoodsBind($parent_admin_id = 0, $admin_id = 0) {
  552. try {
  553. //找到同级产品代理,检测被代理的产品
  554. $front_agent = AgentBind::find()->where(['parent_admin_id' => $parent_admin_id, 'is_delete' => 0, 'type' => 1])
  555. ->select('admin_id')->column();
  556. if ($admin_id) {
  557. $front_agent = array_diff($front_agent, [$admin_id]);
  558. }
  559. $bind_goods = AgentGoodsBindGoods::find()->where(['goods_agent_admin_id' => $front_agent, 'is_delete' => 0, 'status' => [0, 1]])
  560. ->select('cloud_goods_id')->column();
  561. return [
  562. 'code' => 0,
  563. 'msg' => '获取成功',
  564. 'data' => $bind_goods
  565. ];
  566. } catch (\Exception $e) {
  567. return [
  568. 'code' => 1,
  569. 'msg' => $e->getMessage()
  570. ];
  571. }
  572. }
  573. }