CustomerProduct.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace addons\qingdongams\controller;
  3. use addons\qingdongams\model\CustomerProduct as CustomerProductModel;
  4. use addons\qingdongams\model\Staff;
  5. use think\Db;
  6. use think\Exception;
  7. /**
  8. * @desc 操作文档:https://doc.fastadmin.net/qingdongams
  9. * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  10. * @desc 售后微信:qingdong_crm
  11. */
  12. /**
  13. * 客户产品
  14. */
  15. class CustomerProduct extends StaffApi
  16. {
  17. protected $noNeedLogin = [];
  18. protected $noNeedRight = [];
  19. //获取客户产品
  20. public function getList()
  21. {
  22. $limit = input("limit/d", 10);
  23. $customer_id = input("customer_id", 0);
  24. $where = [ 'customer_id' => $customer_id];
  25. $where['create_staff_id']=['in',Staff::getMyStaffIds()];
  26. $records = CustomerProductModel::where($where)->with([
  27. 'customer',
  28. 'createStaff',
  29. 'product'
  30. ])->order('id desc')->paginate($limit);
  31. $this->success('请求成功', $records);
  32. }
  33. //获取列表
  34. public function getSelectList()
  35. {
  36. $customer_id = input("customer_id", 0);
  37. $status = input("status", 0);
  38. $where = ['customer_id' => $customer_id,'status'=>['neq',9]];
  39. if($status){
  40. if($status == 3){
  41. $where[ 'status'] =['in',[3,4]];
  42. }else{
  43. $where[ 'status'] =$status;
  44. }
  45. }
  46. $records = CustomerProductModel::where($where)->with([
  47. 'product'
  48. ])->field('id,product_id,status,pay_date,number,createtime')->order('id desc')->select();
  49. $records=collection($records)->toArray();
  50. foreach ($records as $k=>$v){
  51. $product_id=intval($v['product_id']);
  52. $v['parts']=\addons\qingdongams\model\Parts::where('', 'exp', Db::raw('FIND_IN_SET(' .$product_id. ',product_id)'))->select();
  53. $records[$k]=$v;
  54. }
  55. $this->success('请求成功', $records);
  56. }
  57. //添加客户产品
  58. public function addProduct()
  59. {
  60. $params = $this->request->post();
  61. // 表单验证
  62. if (($result = $this->qingdongamsValidate($params,get_class(), 'create')) !== true) {
  63. $this->error($result);
  64. }
  65. Db::startTrans();
  66. try {
  67. $result = CustomerProductModel::createProduct($params);
  68. Db::commit();
  69. } catch (Exception $e) {
  70. Db::rollback();
  71. $this->error($e->getMessage());
  72. }
  73. if ($result) {
  74. $this->success('创建成功');
  75. }
  76. }
  77. //编辑客户产品
  78. public function editProduct()
  79. {
  80. $id = input('id');
  81. $params = $this->request->post();
  82. $row = CustomerProductModel::where(['id' => $id])->find();
  83. if (empty($row)) {
  84. $this->error('客户产品不存在');
  85. }
  86. // 表单验证
  87. if (($result = $this->qingdongamsValidate($params,get_class(), 'edit')) !== true) {
  88. $this->error($result);
  89. }
  90. Db::startTrans();
  91. try {
  92. $result = CustomerProductModel::updateProduct($params);
  93. Db::commit();
  94. } catch (Exception $e) {
  95. Db::rollback();
  96. $this->error($e->getMessage());
  97. }
  98. if ($result) {
  99. $this->success('编辑成功');
  100. }
  101. }
  102. //获取客户产品详情
  103. public function getProductDetail()
  104. {
  105. $id = input('id');
  106. $detail = CustomerProductModel::where(['id' => $id])->with(['createStaff','customer','product'])->find();
  107. if (empty($detail)) {
  108. $this->error('产品不存在');
  109. }
  110. $this->success('请求成功',$detail);
  111. }
  112. }