CompanyPlatformCatProfit.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\facade\Validate;
  5. //公司平台分类毛利
  6. class CompanyPlatformCatProfit extends Base
  7. {
  8. //列表
  9. public function getList()
  10. {
  11. $param = $this->request->only(['page' => 1, 'size' => 10, 'companyNo', 'platform_id', 'cat_name' => '', 'pid' => 0], 'post', 'trim');
  12. $val = Validate::rule([
  13. 'companyNo|公司编码' => 'require|length:18',
  14. 'platform_id|平台id' => 'require|number|gt:0',
  15. 'pid|父级分类id' => 'require|number|egt:0',
  16. ]);
  17. if ($val->check($param) == false) return json_show(1004, $val->getError());
  18. $where = [
  19. ['a.is_del', '=', 0],
  20. ['a.pid', '=', $param['pid']],
  21. ];
  22. if ($param['cat_name'] != '') $where[] = ['a.cat_name', 'like', '%' . $param['cat_name'] . '%'];
  23. $count = Db::name('cat')
  24. ->alias('a')
  25. ->leftJoin('company_platform_cat_profit b', 'b.cat_id=a.id AND b.is_del=0')
  26. ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
  27. ->where($where)
  28. ->count('a.id');
  29. $list = Db::name('cat')
  30. ->alias('a')
  31. ->field('a.id cat_id,a.cat_name,a.level,p.platform_name,b.rate,b.order_rate,b.money_rate,b.low_rate,b.sale_rate,b.status')
  32. ->leftJoin('company_platform_cat_profit b', 'b.cat_id=a.id AND b.is_del=0 AND b.companyNo=\'' . $param['companyNo'] . '\' AND b.platform_id=\'' . $param['platform_id'] . '\'')
  33. ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0')
  34. ->where($where)
  35. ->order('a.id', 'desc')
  36. ->page($param['page'], $param['size'])
  37. ->select()
  38. ->toArray();
  39. return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list]);
  40. }
  41. //设置
  42. public function set()
  43. {
  44. $param = $this->request->only(['companyNo', 'platform_id', 'cat_id', 'rate', 'order_rate', 'money_rate', 'low_rate', 'sale_rate'], 'post', 'trim');
  45. $val = Validate::rule([
  46. 'companyNo|公司编码' => 'require|length:18',
  47. 'platform_id|平台id' => 'require|number|gt:0',
  48. 'cat_id|分类id' => 'require|number|gt:0',
  49. 'rate|主管利率' => 'require|float|between:0,100',
  50. 'order_rate|预算成本' => 'require|float|between:0,100',
  51. 'money_rate|财务利率' => 'require|float|between:0,100',
  52. 'low_rate|最低利率' => 'require|float|between:0,100',
  53. 'sale_rate|成本售价' => 'require|float|between:0,100',
  54. ]);
  55. if (!$val->check($param)) return json_show(1004, $val->getError());
  56. $rs = Db::name('company_platform_cat_profit')
  57. ->field('id')
  58. ->where([
  59. 'is_del' => 0,
  60. 'companyNo' => $param['companyNo'],
  61. 'platform_id' => $param['platform_id'],
  62. 'cat_id' => $param['cat_id'],
  63. ])
  64. ->findOrEmpty();
  65. $date = date('Y-m-d H:i:s');
  66. if (empty($rs)) {
  67. $rs = Db::name('company_platform_cat_profit')
  68. ->insert([
  69. 'companyNo' => $param['companyNo'],
  70. 'platform_id' => $param['platform_id'],
  71. 'cat_id' => $param['cat_id'],
  72. 'rate' => $param['rate'],
  73. 'order_rate' => $param['order_rate'],
  74. 'money_rate' => $param['money_rate'],
  75. 'low_rate' => $param['low_rate'],
  76. 'sale_rate' => $param['sale_rate'],
  77. 'status' => 1,
  78. 'is_del' => 0,
  79. 'addtime' => $date,
  80. 'updatetime' => $date,
  81. ]);
  82. } else {
  83. $rs = Db::name('company_platform_cat_profit')
  84. ->where(['is_del' => 0, 'id' => $rs['id']])
  85. ->update([
  86. 'rate' => $param['rate'],
  87. 'order_rate' => $param['order_rate'],
  88. 'money_rate' => $param['money_rate'],
  89. 'low_rate' => $param['low_rate'],
  90. 'sale_rate' => $param['sale_rate'],
  91. 'updatetime' => $date
  92. ]);
  93. }
  94. return $rs ? json_show(0, '设置成功') : json_show(1004, '设置失败');
  95. }
  96. //启禁用
  97. // public function status()
  98. // {
  99. // $param = $this->request->only(['cat_id', 'companyNo', 'platform_id', 'status'], 'post', 'trim');
  100. //
  101. // $val = Validate::rule([
  102. // 'cat_id|分类id' => 'require|number|gt:0',
  103. // 'platform_id|平台id' => 'require|number|gt:0',
  104. // 'companyNo|公司编码' => 'require|length:18',
  105. // 'status|状态' => 'require|number|in:0,1',
  106. // ]);
  107. //
  108. // if ($val->check($param) == false) return json_show(1004, $val->getError());
  109. //
  110. // $cat = Db::name('cat')
  111. // ->field('id,level')
  112. // ->where(['id' => $param['cat_id'], 'is_del' => 0])
  113. // ->findOrEmpty();
  114. //
  115. // if (empty($cat)) return json_show(1005, '该分类不存在');
  116. //
  117. // //要操作的分类id集合
  118. // switch ($cat['level']) {
  119. // case 1:
  120. // $first_ids = Db::name('cat')
  121. // ->where(['is_del' => 0, 'pid' => $param['cat_id']])
  122. // ->column('id');
  123. //
  124. // $second_ids = Db::name('cat')
  125. // ->where('is_del', 0)
  126. // ->whereIn('pid', $first_ids)
  127. // ->column('id');
  128. //
  129. // $cat_ids = array_merge($first_ids, $second_ids);
  130. // break;
  131. //
  132. // case 2:
  133. // $cat_ids = Db::name('cat')
  134. // ->where(['is_del' => 0, 'pid' => $param['cat_id']])
  135. // ->column('id');
  136. // break;
  137. // }
  138. //
  139. // $cat_ids[] = $param['cat_id'];
  140. //
  141. // $rs = Db::name('company_platform_cat_profit')
  142. // ->where(['is_del' => 0, 'companyNo' => $param['companyNo'], 'platform_id' => $param['platform_id']])
  143. // ->whereIn('cat_id', $cat_ids)
  144. // ->where('status', '<>', $param['status'])
  145. // ->update([
  146. // 'status' => $param['status'],
  147. // 'updatetime' => date('Y-m-d H:i:s')
  148. // ]);
  149. // return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败,该记录不存在或重复操作');
  150. //
  151. // }
  152. //删除
  153. public function delete()
  154. {
  155. $param = $this->request->only(['companyNo', 'platform_id', 'cat_id'], 'post', 'trim');
  156. $val = Validate::rule([
  157. 'companyNo|公司编码' => 'require|length:18',
  158. 'platform_id|平台id' => 'require|number|gt:0',
  159. 'cat_id|分类id' => 'require|number|gt:0',
  160. ]);
  161. if ($val->check($param) == false) return json_show(1004, $val->getError());
  162. $rs = Db::name('company_platform_cat_profit')
  163. ->where([
  164. 'is_del' => 0,
  165. 'companyNo' => $param['companyNo'],
  166. 'platform_id' => $param['platform_id'],
  167. 'cat_id' => $param['cat_id'],
  168. ])
  169. ->update([
  170. 'is_del' => 1,
  171. 'updatetime' => date('Y-m-d H:i:s')
  172. ]);
  173. return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败');
  174. }
  175. }