Product.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\shop\model\plus\agent;
  3. use app\common\model\plus\agent\Product as AgentProductModel;
  4. use app\common\model\product\Product as ProductModel;
  5. /**
  6. * 分销商用户模型
  7. */
  8. class Product extends AgentProductModel
  9. {
  10. public function getList($product_id)
  11. {
  12. return $this->where('product_id', '=', $product_id)
  13. ->select();
  14. }
  15. /**
  16. * 保存
  17. */
  18. public function edit($params)
  19. {
  20. $this->startTrans();
  21. try {
  22. (new ProductModel())->where('product_id', '=', $params['product_id'])
  23. ->save([
  24. 'is_agent' => $params['is_agent'],
  25. ]);
  26. // 参与分销
  27. if ($params['is_agent'] == 1) {
  28. // 先删除
  29. $model = self::detail($params['product_id']);
  30. if(!$model){
  31. $model = new self();
  32. }
  33. $model->save(array_merge($params, [
  34. 'app_id' => self::$app_id
  35. ]));
  36. }
  37. $this->commit();
  38. return true;
  39. } catch (\Exception $e) {
  40. $this->error = $e->getMessage();
  41. $this->rollback();
  42. return false;
  43. }
  44. }
  45. //设置状态
  46. public function setAgent($productIds, $is_agent)
  47. {
  48. return (new ProductModel)->where('product_id', 'in', $productIds)->save(['is_agent' => $is_agent]);
  49. }
  50. }