Filing.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Exception;
  4. use think\facade\Db;
  5. use think\facade\Validate;
  6. //报备单
  7. class Filing extends Base
  8. {
  9. //列表
  10. public function getList()
  11. {
  12. $data = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => '', 'supplierNo' => ''], 'post');
  13. $where = [['is_del', '=', '0']];
  14. if ($data['cat_id'] != '') $where[] = ['cat_id', '=', $data['cat_id']];
  15. if ($data['start_date'] != '' && $data['end_date'] != '') $where[] = ['addtime', 'between', [$data['start_date'] . ' 00:00:00', $data['end_date'] . ' 23:59:59']];
  16. if ($data['filingCode'] != '') $where[] = ['filingCode', 'like', '%' . $data['filingCode'] . '%'];
  17. if ($data['status'] != '') $where[] = ['status', '=', $data['status']];
  18. if ($data['good_name'] != '') $where[] = ['good_name', 'like', '%' . $data['good_name'] . '%'];
  19. if ($data['companyName'] != '') $where[] = ['companyName', 'like', '%' . $data['companyName'] . '%'];
  20. if ($data['companyCode'] != '') $where[] = ['companyCode', 'like', '%' . $data['companyCode'] . '%'];
  21. if ($data['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $data['orderCode'] . '%'];
  22. if ($data['supplierNo'] != '') $where[] = ['supplierNo', '=', $data['supplierNo']];
  23. $count = Db::name('filing')
  24. ->where($where)
  25. ->count('id');
  26. $list = Db::name('filing')
  27. ->field('id,filingCode,cat_id,good_name,num,wait_num,transfer_num,good_img,price,expect_service,companyName,companyCode,status,addtime,"" catinfo,orderCode,cgd_charge')
  28. ->where($where)
  29. ->page($data['page'], $data['size'])
  30. ->order('id', 'desc')
  31. ->withAttr('good_img', function ($val) {
  32. return explode(',', $val);
  33. })
  34. ->select()
  35. ->toArray();
  36. $all_cat = [];
  37. foreach ($list as &$value) {
  38. if (!isset($all_cat[$value['cat_id']])) $all_cat[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  39. $value['catinfo'] = $all_cat[$value['cat_id']];
  40. }
  41. return json_show(0, '获取报备单列表成功', ['count' => $count, 'list' => $list]);
  42. }
  43. //添加
  44. public function add()
  45. {
  46. $param = $this->request->filter(["trim",'strip_tags'])->only([
  47. 'customerCode',
  48. 'supplierNo',
  49. 'companyName',
  50. 'num',
  51. 'is_determine_price',
  52. 'price' => 0,
  53. 'expect_service_proportion',
  54. 'expect_service',
  55. 'cgd_charge' => 0,
  56. 'brand_id',
  57. 'fill_url',
  58. 'preservation_day',
  59. 'delivery_day',
  60. 'make_day',
  61. 'tax',
  62. 'unit_id',
  63. 'cat_id',
  64. 'spec_list' => [],
  65. 'good_name',
  66. 'origin_place',
  67. 'delivery_place',
  68. 'weight',
  69. 'supply_area',
  70. 'pay_way',
  71. 'gold_weight',
  72. 'noble_metal',
  73. 'config',
  74. 'other_config',
  75. 'remark',
  76. 'cost_desc',
  77. 'good_img'], 'post');
  78. $val = Validate::rule([
  79. 'customerCode|业务公司' => 'require|max:255',
  80. 'supplierNo|供应商' => 'require|max:255',
  81. 'companyName|客户名称' => 'require|max:255',
  82. 'num|销售数量' => 'require|number|gt:0|lt:999999999',
  83. 'is_determine_price|是否确定售价' => 'require|number|in:1,0',
  84. 'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
  85. 'expect_service_proportion|期望服务费比例' => 'require|float|between:0,100',
  86. 'expect_service|期望服务费' => 'require|float|max:99999999.99',
  87. 'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
  88. 'brand_id|品牌' => 'require|number|gt:0',
  89. 'fill_url|报备附件' => 'require',
  90. 'preservation_day|有效期' => 'require|number|max:999999999',
  91. 'delivery_day|物流时间' => 'require|number|max:999999999',
  92. 'make_day|生产工期' => 'require|number|max:999999999',
  93. 'tax|税点' => 'require|number|between:0,100',
  94. 'unit_id|单位' => 'require|number|gt:0',
  95. 'cat_id|分类' => 'require|number|gt:0',
  96. 'spec_list|规格类型' => 'array|max:100',
  97. 'good_name|商品名称' => 'require|max:255',
  98. 'origin_place|产地' => 'require|array|length:3',
  99. 'delivery_place|发货地' => 'require|array|length:3',
  100. 'weight|总重量' => 'require|float|max:99999999.99',
  101. 'supply_area|供货区域' => 'require|number|in:1,2',
  102. 'pay_way|付款方式' => 'require|number|in:0,1,2',
  103. 'remark|采购备注' => 'require|max:255',
  104. 'cost_desc|工艺说明' => 'max:255',
  105. 'good_img|商品图片' => 'require|array|max:10',
  106. ]);
  107. if (!$val->check($param)) return json_show(1004, $val->getError());
  108. //如果是贵金属的话,额外判断
  109. $cat = made($param['cat_id']);
  110. if (isset($cat[0]['id']) && $cat[0]['id'] == 6) {
  111. $val_gold = Validate::rule([
  112. 'gold_weight|贵金属重量' => 'require|float|max:99999999.99',
  113. 'noble_metal|贵金属类型' => 'require|number|in:1,2,3',
  114. 'config|配置要求' => 'require|max:255',
  115. 'other_config|其他配置要求' => 'require|max:255',
  116. ]);
  117. if (!$val_gold->check($param)) return json_show(1004, $val_gold->getError());
  118. }
  119. $val2 = Validate::rule([
  120. 'spec_id|规格id' => 'require|number|gt:0',
  121. 'spec_value_id|规格值id' => 'require|number|gt:0',
  122. ]);
  123. $all_spec = Db::name('specs')
  124. ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
  125. ->column('spec_name', 'id');
  126. $all_spec_value = Db::name('spec_value')
  127. ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
  128. ->column('spec_value', 'id');
  129. foreach ($param['spec_list'] as &$spec_list) {
  130. if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
  131. $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
  132. $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
  133. }
  134. if ($param['is_determine_price'] == 1) $param['cgd_charge'] = round(bcsub($param['price'], $param['expect_service'], 3), 2);//确定售价时,采购价=售价-服务费
  135. else $param['price'] = round(bcadd($param['cgd_charge'], $param['expect_service'], 3), 2);//不确定售价时,售价=采购价+服务费
  136. $userCommon = \app\admin\common\User::getIns();
  137. $names = $userCommon->handle('getCodeAndName', ['code' => [$param['customerCode'], $param['supplierNo']]]);
  138. if (!isset($names['data'][$param['customerCode']]) || $names['data'][$param['customerCode']] == '') return json_show(1004, '该业务公司不存在');
  139. if (!isset($names['data'][$param['supplierNo']]) || $names['data'][$param['supplierNo']] == '') return json_show(1004, '该供应商不存在');
  140. $rs = Db::name('filing')
  141. ->strict(false)
  142. ->insert(array_merge($param, [
  143. 'customerName' => $names['data'][$param['customerCode']],
  144. 'supplierName' => $names['data'][$param['supplierNo']],
  145. 'filingCode' => makeNo('BM'),
  146. 'service_proportion' => $param['expect_service_proportion'],//服务费比例与期望服务费比例一致
  147. 'service_charge' => $param['expect_service'],//服务费与期望服务费一致
  148. 'specinfo' => json_encode($param['spec_list']),
  149. "wait_num"=>$param["num"],
  150. 'send_way' => 2,
  151. 'cert_fee' => 0,
  152. 'pakge_fee' => 0,
  153. 'cost_fee' => 0,
  154. 'mark_fee' => 0,
  155. 'demo_fee' => 0,
  156. 'open_fee' => 0,
  157. 'fill_url' =>$param['fill_url'],
  158. 'delivery_fee' => 0,
  159. 'is_gold_price' => 0,
  160. 'is_diff' => 0,
  161. 'apply_id' => $this->uid,
  162. 'apply_name' => $this->uname,
  163. 'status' => 0,
  164. 'is_del' => 0,
  165. 'addtime' => date('Y-m-d H:i:s'),
  166. 'updaterid' => $this->uid,
  167. 'updater' => $this->uname,
  168. 'updatetime' => date('Y-m-d H:i:s'),
  169. 'gold_weight' => $param['gold_weight'] ?? 0,
  170. 'noble_metal' => $param['noble_metal'] ?? 0,
  171. 'config' => $param['config'] ?? '',
  172. 'other_config' => $param['other_config'] ?? '',
  173. 'good_img' => implode(',', $param['good_img']),
  174. 'origin_place' => implode(',', $param['origin_place']),
  175. 'delivery_place' => implode(',', $param['delivery_place']),
  176. ]));
  177. return $rs ? json_show(0, '创建报备单成功') : json_show(1004, '创建报备单失败');
  178. }
  179. //添加
  180. public function save()
  181. {
  182. $param = $this->request->filter(['trim','strip_tags'])->only(["id",
  183. 'customerCode',
  184. 'supplierNo',
  185. 'companyName',
  186. 'num',
  187. 'is_determine_price',
  188. 'price' => 0,
  189. 'expect_service_proportion',
  190. 'expect_service',
  191. 'cgd_charge' => 0,
  192. 'brand_id',
  193. 'preservation_day',
  194. 'delivery_day',
  195. 'make_day',
  196. 'tax',
  197. 'fill_url' ,
  198. 'unit_id',
  199. 'cat_id',
  200. 'spec_list' => [],
  201. 'good_name',
  202. 'origin_place',
  203. 'delivery_place',
  204. 'weight',
  205. 'supply_area',
  206. 'pay_way',
  207. 'gold_weight',
  208. 'noble_metal',
  209. 'config',
  210. 'other_config',
  211. 'remark',
  212. 'cost_desc',
  213. 'good_img'], 'post');
  214. $val = Validate::rule([
  215. 'id|报备单主键id' => 'require',
  216. 'customerCode|业务公司' => 'require|max:255',
  217. 'supplierNo|供应商' => 'require|max:255',
  218. 'companyName|客户名称' => 'require|max:255',
  219. 'num|销售数量' => 'require|number|gt:0|lt:999999999',
  220. 'is_determine_price|是否确定售价' => 'require|number|in:1,0',
  221. 'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
  222. 'expect_service_proportion|期望服务费比例' => 'require|float|between:0,100',
  223. 'expect_service|期望服务费' => 'require|float|max:99999999.99',
  224. 'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
  225. 'brand_id|品牌' => 'require|number|gt:0',
  226. 'preservation_day|有效期' => 'require|number|max:999999999',
  227. 'delivery_day|物流时间' => 'require|number|max:999999999',
  228. 'make_day|生产工期' => 'require|number|max:999999999',
  229. 'fill_url|报备附件' =>"require",
  230. 'tax|税点' => 'require|number|between:0,100',
  231. 'unit_id|单位' => 'require|number|gt:0',
  232. 'cat_id|分类' => 'require|number|gt:0',
  233. 'spec_list|规格类型' => 'array|max:100',
  234. 'good_name|商品名称' => 'require|max:255',
  235. 'origin_place|产地' => 'require|array|length:3',
  236. 'delivery_place|发货地' => 'require|array|length:3',
  237. 'weight|总重量' => 'require|float|max:99999999.99',
  238. 'supply_area|供货区域' => 'require|number|in:1,2',
  239. 'pay_way|付款方式' => 'require|number|in:0,1,2',
  240. 'remark|采购备注' => 'require|max:255',
  241. 'cost_desc|工艺说明' => 'max:255',
  242. 'good_img|商品图片' => 'require|array|max:10',
  243. ]);
  244. if (!$val->check($param)) return json_show(1004, $val->getError());
  245. //如果是贵金属的话,额外判断
  246. $cat = made($param['cat_id']);
  247. if (isset($cat[0]['id']) && $cat[0]['id'] == 6) {
  248. $val_gold = Validate::rule([
  249. 'gold_weight|贵金属重量' => 'require|float|max:99999999.99',
  250. 'noble_metal|贵金属类型' => 'require|number|in:1,2,3',
  251. 'config|配置要求' => 'require|max:255',
  252. 'other_config|其他配置要求' => 'require|max:255',
  253. ]);
  254. if (!$val_gold->check($param)) return json_show(1004, $val_gold->getError());
  255. }
  256. $val2 = Validate::rule([
  257. 'spec_id|规格id' => 'require|number|gt:0',
  258. 'spec_value_id|规格值id' => 'require|number|gt:0',
  259. ]);
  260. $all_spec = Db::name('specs')
  261. ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
  262. ->column('spec_name', 'id');
  263. $all_spec_value = Db::name('spec_value')
  264. ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
  265. ->column('spec_value', 'id');
  266. foreach ($param['spec_list'] as &$spec_list) {
  267. if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
  268. $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
  269. $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
  270. }
  271. if ($param['is_determine_price'] == 1) $param['cgd_charge'] = round(bcsub($param['price'], $param['expect_service'], 3), 2);//确定售价时,采购价=售价-服务费
  272. else $param['price'] = round(bcadd($param['cgd_charge'], $param['expect_service'], 3), 2);//不确定售价时,售价=采购价+服务费
  273. $userCommon = \app\admin\common\User::getIns();
  274. $names = $userCommon->handle('getCodeAndName', ['code' => [$param['customerCode'], $param['supplierNo']]]);
  275. if (!isset($names['data'][$param['customerCode']]) || $names['data'][$param['customerCode']] == '') return json_show(1004, '该业务公司不存在');
  276. if (!isset($names['data'][$param['supplierNo']]) || $names['data'][$param['supplierNo']] == '') return json_show(1004, '该供应商不存在');
  277. $rs = Db::name('filing')
  278. ->save(array_merge($param, [
  279. 'customerName' => $names['data'][$param['customerCode']],
  280. 'supplierName' => $names['data'][$param['supplierNo']],
  281. 'service_proportion' => $param['expect_service_proportion'],//服务费比例与期望服务费比例一致
  282. 'service_charge' => $param['expect_service'],//服务费与期望服务费一致
  283. 'specinfo' => json_encode($param['spec_list']),
  284. 'wait_num'=>$param['num'],
  285. 'send_way' => 2,
  286. "staus"=>0,
  287. "is_check"=>0,
  288. "fill_url"=>$param["fill_url"],
  289. 'apply_id' => $this->uid,
  290. 'apply_name' => $this->uname,
  291. 'updaterid' => $this->uid,
  292. 'updater' => $this->uname,
  293. 'updatetime' => date('Y-m-d H:i:s'),
  294. 'gold_weight' => $param['gold_weight'] ?? 0,
  295. 'noble_metal' => $param['noble_metal'] ?? 0,
  296. 'config' => $param['config'] ?? '',
  297. 'other_config' => $param['other_config'] ?? '',
  298. 'good_img' => implode(',', $param['good_img']),
  299. 'origin_place' => implode(',', $param['origin_place']),
  300. 'delivery_place' => implode(',', $param['delivery_place']),
  301. ]));
  302. return $rs ? json_show(0, '报备单更新成功') : json_show(1004, '报备单更新失败');
  303. }
  304. //详情
  305. public function detail()
  306. {
  307. $param = $this->request->only(['id' => 0], 'post', 'trim');
  308. $rs = Db::name('filing')
  309. ->alias('a')
  310. ->field('a.*,b.brand_name,d.unit unit_name,p.platform_name,"" cat_info')
  311. ->leftJoin('brand b', 'b.id=a.brand_id')
  312. ->leftJoin('unit d', 'd.id=a.unit_id')
  313. ->leftJoin('platform p', 'p.id=a.platform_id')
  314. ->where(['a.is_del' => 0, 'a.id' => $param['id']])
  315. ->withAttr('specinfo', function ($val) {
  316. return json_decode($val);
  317. })
  318. ->withAttr('good_img', function ($val) {
  319. return explode(',', $val);
  320. })->withAttr('origin_place', function ($val) {
  321. return explode(',', $val);
  322. })->withAttr('delivery_place', function ($val) {
  323. return explode(',', $val);
  324. })->withAttr('cat_info', function ($val, $da) {
  325. return made($da['cat_id']);
  326. })
  327. ->findOrEmpty();
  328. if(!empty($rs['origin_place']))$origin = ["provice_code"=>$rs['origin_place'][0]??"","city_code"=>$rs['origin_place'][1]??'','area_code'=>$rs['origin_place'][2]??''];
  329. $rs["origin_place_cn"] = GetAddr(json_encode($origin));
  330. if(!empty($rs['delivery_place']))$deliev = ['provice_code'=>$rs['delivery_place'][0]??'','city_code'=>$rs['delivery_place'][1]??'','area_code'=>$rs['delivery_place'][2]??''];
  331. $rs['delivery_place_cn'] = GetAddr(json_encode($deliev));
  332. return json_show(0, '获取报备单详情成功', $rs);
  333. // return FilingLogic::detail($param);
  334. }
  335. //0 待审核 1 待修改 不合规 2 合规可转单 3 部分 4 转单成功 5取消转单
  336. public function status()
  337. {
  338. if ($this->level != 2) return json_show(1004, '业务公司账号不能审核');
  339. $param = $this->request->only(['id', 'companyCode', 'plat_code' => '','platform_id',"remark"=>"",'is_check'=>''], 'post');
  340. $val = Validate::rule([
  341. 'id' => 'require|number|gt:0',
  342. 'companyCode|客户' => 'requireIf:is_check,1|length:18',
  343. 'platform_id|平台id' => 'requireIf:is_check,1|number|gt:0',
  344. 'plat_code|平台商品编号' => 'requireIf:is_check,1|max:255',
  345. "is_check|是否合规"=> 'require|number|in:1,2',
  346. "remark|备注"=> 'requireIf:is_check,2|number|in:1,2',
  347. ]);
  348. if (!$val->check($param)) return json_show(1004, $val->getError());
  349. $rs = Db::name('filing')
  350. ->field('id,status,is_determine_price,price,cgd_charge,platform_id,customerCode,customerName')
  351. ->where(['is_del' => 0, 'id' => $param['id'],"status"=>0])
  352. ->findOrEmpty();
  353. if (empty($rs)) return json_show(1005, '该报备单不存在或不允许审核');
  354. $userCommon = \app\admin\common\User::getIns();
  355. $company = $userCommon->handle('cInfo', ['companyNo' => $param['companyCode']]);
  356. if (!isset($company['data'])) return json_show(1005, '该客户不存在');
  357. $tmp = Db::name('platform')
  358. ->where(['is_del' => 0, 'id' => $param['platform_id']])
  359. ->field('id,is_select_pay_rate,status')
  360. ->findOrEmpty();
  361. if (empty($tmp)) return json_show(1005, '该平台不存在');
  362. if ($tmp['status'] != 1) return error_show(1004, "平台信息已禁用");
  363. if($tmp['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$rs['customerCode']))return
  364. error_show(1004, "平台渠道包含当前业务公司 {$rs['customerName']}");
  365. //校验支付渠道中的业务公司是否与报备单业务公司重复
  366. $update = array_merge($param, [
  367. 'companyName' => $company['data']['companyName'],
  368. "status"=>$param["is_check"],
  369. 'updaterid' => $this->uid,
  370. 'updater' => $this->uname,
  371. 'updatetime' => date('Y-m-d H:i:s'),
  372. ]);
  373. //
  374. // if ($rs['is_determine_price'] == 1) $update['cgd_charge'] = round(bcsub($rs['price'], $param['service_charge'], 3), 2);//确定售价时,采购价=售价-服务费
  375. // else $update['price'] = round(bcadd($rs['cgd_charge'], $param['service_charge'], 3), 2);//不确定售价时,售价=采购价+服务费
  376. $res = Db::name('filing')
  377. ->where(['is_del' => 0, 'id' => $param['id']])
  378. ->whereIn('status', [0, 2])
  379. ->update($update);
  380. return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  381. // return FilingLogic::status($param);
  382. }
  383. //取消转单
  384. public function cancel()
  385. {
  386. if ($this->level == 1) return json_show(1004, '超管不允许操作');
  387. $param = $this->request->only(['id'], 'post');
  388. $where = [
  389. ['is_del', '=', 0],
  390. ['id', '=', $param['id']],
  391. ['status', 'in', [0, 1, 2, 4]]
  392. ];
  393. $rs = Db::name('filing')
  394. ->field('id,status,supplierNo')
  395. ->where($where)
  396. ->findOrEmpty();
  397. if (empty($rs)) return json_show(1005, '该报备单不存在或不允许取消');
  398. if ($this->level == 2) {
  399. $supp = get_personid_by_supplierNo([$rs['supplierNo']]);
  400. if ($this->uid != $supp[$rs['supplierNo']]) return json_show(1004, '只有供应商负责人才能操作');
  401. }
  402. $res = Db::name('filing')
  403. ->where($where)
  404. ->update(['status' => 5, 'updatetime' => date('Y-m-d H:i:s'), 'updaterid' => $this->uid, 'updater' => $this->uname,]);
  405. return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  406. }
  407. //转单
  408. public function transfer()
  409. {
  410. if ($this->level == 1) return json_show(1004, '超管不允许操作');
  411. $param = $this->request->only([
  412. 'id',
  413. 'addr_list'=>[],
  414. "customerCode"=>""], 'post');
  415. $val = Validate::rule([
  416. 'id|报备的主键id' => 'require|number|gt:0',
  417. "customerCode|客户编号"=>"require|max:255",
  418. 'addr_list|收货地址' => 'require|array|max:100',
  419. ]);
  420. if (!$val->check($param)) return json_show(1004, $val->getError());
  421. $val2 = Validate::rule([
  422. 'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
  423. 'contactor|联系人' => 'require|max:255',
  424. 'mobile|联系电话' => 'require|mobile',
  425. 'addr_code|收货省市区编码' => 'require|array|length:3',
  426. 'addr|详细地址' => 'require|max:255',
  427. ]);
  428. foreach ($param['addr_list'] as $addr_list) {
  429. if (!$val2->check($addr_list)) return json_show(1004, $val2->getError());
  430. }
  431. $filing = Db::name('filing')
  432. ->field(true)
  433. ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
  434. ->findOrEmpty();
  435. if (empty($filing)) return json_show(1005, '该报备单不存在或不允许转单');
  436. $send_num = array_sum(array_column($param['addr_list'], 'receipt_quantity'));
  437. $wait_num = $filing['wait_num'] - $send_num ;
  438. if ($wait_num<0) return json_show(1004, '收货地址的收货总数超过报备单可转单数量');
  439. $userCommon = \app\admin\common\User::getIns();
  440. $supplier = $userCommon->handle('sInfo', ['code' => $filing['supplierNo']]);
  441. $names = $userCommon->handle('getCodeAndName', ['code' => [ $param['customerCode']]]);
  442. if (!isset($names['data'])) return json_show(1005, '该客户不存在');
  443. //level3账号都可以操作
  444. //level2账号的话,只有供应商负责人能操作
  445. if (($this->level == 2) && ($this->uid != $supplier['data']['personid'])) return json_show(1004, '只有供应商负责人才能操作');
  446. $date = date('Y-m-d H:i:s');
  447. Db::startTrans();
  448. try {
  449. $order_type = 4;//报备商品
  450. $order_source = 7;//报备转单
  451. $spuCode = makeNo('SKU');
  452. //商品表
  453. $goodIn= Db::name('good_zixun')
  454. ->insert([
  455. 'spuCode' => $spuCode,
  456. 'good_name' => $filing['good_name'],
  457. 'brand_id' => $filing['brand_id'],
  458. 'cat_id' => $filing['cat_id'],
  459. 'good_unit' => $filing['unit_id'],
  460. 'good_type' => 0,
  461. 'moq' => 1,
  462. 'customized' => $filing['make_day'],
  463. 'tax' => $filing['tax'],
  464. 'platform_id' => $filing['platform_id'],
  465. 'supplierNo' => $filing['supplierNo'],
  466. 'supplierName' => $supplier['data']['name'],
  467. 'is_auth' => 0,
  468. 'craft_desc' => $filing['good_name'],
  469. 'good_remark' => '',
  470. 'good_img' => $filing['good_img'],
  471. 'good_thumb_img' => '',
  472. 'good_info_img' => '',
  473. 'status' => 1,
  474. 'createrid' => $filing['updaterid'],
  475. 'creater' => $filing['updater'],
  476. 'is_del' => 0,
  477. 'addtime' => $date,
  478. 'updatetime' => $date,
  479. 'specinfo' => $filing['specinfo'],
  480. 'work_day' => $filing['make_day'],
  481. 'noble_metal' => $filing['noble_metal'],
  482. 'is_gold_price' => $filing['is_gold_price'],
  483. 'good_weight' => $filing['gold_weight'],
  484. 'config' => $filing['config'],
  485. 'other_config' => $filing['other_config'],
  486. 'weight' => $filing['weight'],
  487. 'supply_area' => $filing['supply_area'],
  488. 'is_diff' => $filing['is_diff'],
  489. 'pay_way' => $filing['pay_way'],
  490. 'send_way' => $filing['send_way'],
  491. 'companyNo' => $filing['customerCode'],
  492. 'companyName' => $filing['customerName'],
  493. 'proof_type' => '',
  494. 'proof_url' => '',
  495. 'order_type' => $order_type
  496. ]);
  497. if($goodIn==false) throw new \Exception("商品录入商品库失败");
  498. $orderCode = makeNo('QR');
  499. //订单表
  500. //sale
  501. $sale_id = Db::name('sale')->insertGetId([
  502. 'orderCode' => $orderCode,
  503. 'apply_id' => $filing['updaterid'],
  504. 'apply_name' => $filing['updater'],
  505. 'order_type' => $order_type,//报备商品
  506. 'order_source' => $order_source,//报备转单
  507. 'platform_id' => $filing['platform_id'],
  508. 'good_code' => $spuCode,
  509. 'skuCode' => '',
  510. 'cat_id' => $filing['cat_id'],
  511. 'good_name' => $filing['good_name'],
  512. 'good_num' => $filing['num'],
  513. 'good_type' => 1,
  514. 'origin_price' => $filing['cgd_charge'],
  515. 'sale_price' => $filing['price'],
  516. 'total_price' => round(bcmul($filing['price'], $filing['num'], 3), 2),
  517. 'post_fee' => 0,
  518. 'is_diff' => $filing['is_diff'],
  519. 'is_activity' => 0,
  520. 'activity_code' => '',
  521. 'is_stock' => 0,
  522. 'customer_code' => $param['customerCode'],
  523. 'customerName' => $names['data'][$param['customerCode']]??"",
  524. 'supplierNo' => $filing['customerCode'],
  525. 'supplierName' => $filing['customerName'],
  526. 'supNo' => $filing['supplierNo'],
  527. 'supName' => $filing['supplierName'],
  528. 'zxNo' => '',
  529. 'platform_order' =>$filing['filingCode'],
  530. 'send_num' => 0,
  531. 'wsend_num' => $filing['num'],
  532. 'th_num' => 0,
  533. 'th_fee' => 0,
  534. 'send_status' => 1,
  535. 'send_type' => 1,//直接发货
  536. 'remark' => '',
  537. 'status' => 0,
  538. 'is_del' => 0,
  539. 'proof_id' => 0,
  540. 'other_orderNo' => '',
  541. 'workNo' => '',
  542. 'poNo' => '',
  543. 'use_order' => 0,
  544. 'good_weight' => 0,
  545. 'gold_price' => 0,
  546. 'cost_price' => $filing['cost_fee'],
  547. 'diff_weight' => 0,
  548. 'diff_fee' => 0,
  549. 'returnCode' => '',
  550. 'addtime' => $date,
  551. 'updatetime' => $date,
  552. 'cgderid' => $supplier['data']['personid'],
  553. 'cgder' => $supplier['data']['person'],
  554. 'good_createrid' => $filing['updaterid'],
  555. 'good_creater' => $filing['updater'],
  556. ]);
  557. if($sale_id==false) throw new \Exception('订单生成失败');
  558. //仓库
  559. $wsm = Db::name('warehouse_info')
  560. ->field('id,wsm_code')
  561. ->where(['supplierNo' => $filing['supplierNo'], 'companyNo' => $filing['customerCode'], 'is_del' => 0])
  562. ->findOrEmpty();
  563. if (empty($wsm)) {
  564. $wsm_code = makeNo('WSM');
  565. $ws= Db::name('warehouse_info')->insert([
  566. 'wsm_code' => $wsm_code,
  567. 'name' => $supplier['data']['name'],
  568. 'wsm_type' => 2,
  569. 'supplierNo' => $supplier['data']['code'],
  570. 'addr' => '',
  571. 'addrs_code' => '',
  572. 'contactor' => 0,
  573. 'contactor_name' => 0,
  574. 'mobile' => '',
  575. 'position' => '',
  576. 'companyNo' => $filing['supplierNo'],
  577. 'status' => 1,
  578. 'is_del' => 0,
  579. 'addtime' => $date,
  580. 'updatetime' => $date,
  581. ]);
  582. if($ws==false)throw new \Exception('仓库生成失败');
  583. } else $wsm_code = $wsm['wsm_code'];
  584. //采购单
  585. $cgdCode = makeNo('CG');
  586. $cg= Db::name('purchease_order')->insert([
  587. 'cgdNo' => $cgdCode,
  588. 'bkcode' => '',
  589. 'wsm_code' => $wsm_code,
  590. 'cgder' => $supplier['data']['person'],
  591. 'cgder_id' => $supplier['data']['personid'],
  592. 'spuCode' => $spuCode,
  593. 'good_name' => $filing['good_name'],
  594. 'good_num' => $filing['num'],
  595. 'good_price' => $filing['cgd_charge'],
  596. 'total_fee' => round(bcmul($filing['cgd_charge'], $filing['num']), 2),
  597. 'pakge_fee' => $filing['pakge_fee'],
  598. 'cert_fee' => $filing['cert_fee'],
  599. 'open_fee' => $filing['open_fee'],
  600. 'delivery_fee' => $filing['delivery_fee'],
  601. 'mark_fee' => $filing['mark_fee'],
  602. 'demo_fee' => $filing['demo_fee'],
  603. 'diff_weight' => '0',
  604. 'diff_fee' => '0',
  605. 'gold_price' => '0',
  606. 'supplierNo' => $filing['supplierNo'],
  607. 'supplier_name' => $filing['supplierName'],
  608. 'companyNo' => $filing['customerCode'],
  609. 'companyName' => $filing['customerName'],
  610. 'send_status' => 1,
  611. 'send_num' => '0',
  612. 'wsend_num' => $filing['num'],
  613. 'remark' => '',
  614. 'status' => 0,
  615. 'lasttime' => $date,
  616. 'is_del' => 0,
  617. 'order_type' => $order_type,
  618. 'order_source' => $order_source,
  619. 'good_type' => 1,
  620. 'addtime' => $date,
  621. 'updatetime' => $date,
  622. 'good_createrid' => $filing['updaterid'],
  623. 'good_creater' => $filing['updater'],
  624. ]);
  625. if($cg==false)throw new \Exception('采购单生成失败');
  626. //台账
  627. $standing_bood_data = [
  628. 'standBookNo' => makeNo('IO'),
  629. 'orderCode' => $orderCode,
  630. 'sale_id' => $sale_id,
  631. 'customer_code' => $filing['companyCode'],
  632. 'supplierNo' => $filing['supplierNo'],
  633. 'order_type' => $order_type,
  634. 'order_source' => $order_source,
  635. 'spuCode' => $spuCode,
  636. 'addtime' => $date,
  637. 'updatetime' => $date,
  638. 'cgdNo' => $cgdCode,
  639. ];
  640. $i = 0;
  641. $order_send_insert = [];
  642. foreach ($param['addr_list'] as $addr) {
  643. //地址addr
  644. $addrid = Db::name('order_addr')->insertGetId([
  645. 'orderCode' => $orderCode,
  646. 'addr' => $addr['addr'],
  647. 'addr_code' => implode(',', $addr['addr_code']),
  648. 'contactor' => $addr['contactor'],
  649. 'mobile' => $addr['mobile'],
  650. 'customer_code' => $param['customerCode'],
  651. 'post_fee' => 0,
  652. 'receipt_quantity' => $addr['receipt_quantity'],
  653. 'is_del' => 0,
  654. 'addtime' => $date,
  655. 'updatetime' => $date,
  656. ]);
  657. if($addrid==false)throw new \Exception('地址生成失败');
  658. //发货单
  659. $outCode = makeNo('DF');
  660. //改变编码规则,将原来的编码后两位换成序列号
  661. //str_pad字符串填充
  662. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  663. $send= Db::name('order_out')->insert([
  664. 'orderCode' => $orderCode,
  665. 'outCode' => $outCode,
  666. 'apply_id' => $filing['updaterid'],
  667. 'apply_name' => $filing['updater'],
  668. 'addrid' => $addrid,
  669. 'post_name' => '',
  670. 'post_code' => '',
  671. 'post_fee' => 0,
  672. 'sendtime' => $date,
  673. 'send_num' => $addr['receipt_quantity'],
  674. 'check_num' => 0,
  675. 'error_num' => 0,
  676. 'wsm_code' => $wsm_code,
  677. 'order_type' => $order_type,
  678. 'status' => 0,
  679. 'addtime' => $date,
  680. 'updatetime' => $date,
  681. ]);
  682. if($send==false) throw new \Exception('发货单生成失败');
  683. $standing_bood_data['outCode'][] = $outCode;
  684. $order_send_insert[] = [
  685. 'cgdNo' => $cgdCode,
  686. 'outCode' => $outCode,
  687. 'send_num' => $addr['receipt_quantity'],
  688. 'bnCode' => '',
  689. 'status' => 1,
  690. 'addtime' => $date,
  691. 'updatetime' => $date,
  692. ];
  693. $i++;
  694. }
  695. //更新报备单
  696. $fillup= Db::name('filing')
  697. ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
  698. ->update([
  699. 'status' =>$wait_num>0?3:4,
  700. 'wait_num' =>$wait_num,
  701. 'transfer_num' =>$filing['transfer_num']+$send_num,
  702. 'updatetime' => $date,
  703. 'spuCode' => $spuCode,
  704. 'orderCode' =>$filing["orderCode"].$orderCode.",",
  705. 'reason' => '',
  706. 'updaterid' => $this->uid,
  707. 'updater' => $this->uname]);
  708. if($fillup==false)throw new \Exception('报备单更新失败');
  709. //待办已办先不处理
  710. //关联表
  711. $gu= Db::name('order_num')
  712. ->insert([
  713. 'orderCode' => $orderCode,
  714. 'cgdNo' => $cgdCode,
  715. 'spuCode' => $spuCode,
  716. 'companyNo' => $filing['customerCode'],
  717. 'good_num' => $filing['num'],
  718. 'wsend_num' => $filing['num'],
  719. 'send_num' => 0,
  720. 'wait_num' => $filing['num'],
  721. ]);
  722. if($gu==false) throw new \Exception('关联表新建失败');
  723. if ($order_send_insert) Db::name('order_send')->insertAll($order_send_insert);
  724. //处理台账
  725. if (isset($standing_bood_data['outCode']) && is_array($standing_bood_data['outCode'])) $standing_bood_data['outCode'] = implode(',', $standing_bood_data['outCode']);
  726. Db::name('standing_book')->insert($standing_bood_data);
  727. Db::commit();
  728. return json_show(0, '转单成功');
  729. } catch (Exception $exception) {
  730. Db::rollback();
  731. return json_show(1005, '转单失败,' . $exception->getMessage());
  732. }
  733. }
  734. //订单录入
  735. public function orderAdd()
  736. {
  737. $param = $this->request->param([
  738. "companyNo" => '',
  739. "poCode" => "",
  740. "workCode" => "",
  741. "khNo" => "",
  742. "qrdType" => 3,
  743. "goodName" => "",
  744. "tax" => "",
  745. "goodNum" => "",
  746. "goodPrice" => "",
  747. "sale_total" => "",
  748. "goodUnit" => "",
  749. "mobile" => "",
  750. "addr" => "",
  751. "addr_code" => "",
  752. "contactor" => "",
  753. "sendtime" => "",
  754. "cat_id" => '',
  755. "supplierNo" => "",
  756. "cgdPrice" => "",
  757. "cgd_total" => "",
  758. "platform_id" => "0",
  759. ], "post", "trim");
  760. $valid = Validate::rule([
  761. "companyNo|业务公司编号" => "require|max:255|min:1",
  762. "supplierNo|业务公司编号" => "require|max:255|min:1",
  763. "poCode|PO编号" => "require|max:255|min:1",
  764. "khNo|客户公司编号" => "require|max:255|min:1",
  765. "qrdType|订单类型" => "require|number|in:1,2,3",
  766. "goodName|商品名称" => "require|max:255|min:1",
  767. "goodUnit|商品单位" => "require|number|gt:0",
  768. "tax|税率" => "require|number|gt:0",
  769. "goodNum|商品数量" => "require|number|gt:0",
  770. "sale_total|销售总额" => "require|float|gt:0",
  771. "cgd_total|采购总额" => "require|float|gt:0",
  772. // "goodPrice|商品单价" => "require|float|gt:0",
  773. "mobile|联系人电话" => "require|number|mobile",
  774. "contactor|联系人" => "require|max:255|min:1",
  775. "addr|收货地址" => "require|max:255|min:1",
  776. "sendtime|发货时间" => "require|date",
  777. "cat_id|商品分类id" => "require|number|gt:0",
  778. // "cgdPrice|采购单价" => "require|float|gt:0",
  779. "platform_id|平台" => "require|number"
  780. ]);
  781. if ($valid->check($param) == false) return error_show(1004, $valid->getError());
  782. $qrdcode = makeNo("QR");
  783. $cgddcode = makeNo("CG");
  784. $goodCode = makeNo("SKU");
  785. $userCommon = \app\admin\common\User::getIns();
  786. $tmp = $userCommon->handle('getCodeAndName',['code'=>[$param['khNo'],$param['supplierNo'],$param['companyNo']]]);
  787. if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
  788. if(!isset($tmp['data'][$param['khNo']])) return json_show(1004, "未找到客户数据");
  789. if(!isset($tmp['data'][$param['supplierNo']])) return json_show(1004, "未找到平台供应商数据");
  790. if(!isset($tmp['data'][$param['companyNo']])) return json_show(1004, "未找到平台业务公司数据");
  791. $payinfo = Db::name("platform")->where(["id"=> $param['platform_id'],"is_del"=>0])->findOrEmpty();
  792. if (empty($payinfo)) return error_show(1004, "平台信息未找到");
  793. if ($payinfo['status'] != 1) return error_show(1004, "平台信息已禁用");
  794. if($payinfo['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$param['companyNo']))return error_show(1004, "平台渠道包含当前业务公司 {$tmp['data'][$param['companyNo']]}");
  795. $supplierinfo = $userCommon->handle("hqInfo",["code"=>$param['supplierNo']]);
  796. if(!isset($supplierinfo['data'])|| empty($supplierinfo['data'])) return json_show(1004, "未找到供应商公司数据");
  797. $person =$supplierinfo['data']['child']??["person"=>'',"person_id"=>0];
  798. if($param['companyNo']== $supplierinfo['data']['relation_code']) return json_show(1004,'供应商和业务公司不能为同一家公司');
  799. $cgdprice = round($param['cgd_total']/$param['goodNum'],2);
  800. $saleprice = round($param['sale_total']/$param['goodNum'],2);
  801. $qrddata = [
  802. "orderCode" => $qrdcode,
  803. "apply_id" => $this->uid,
  804. "apply_name" => $this->uname,
  805. "order_type" => $param['qrdType'],
  806. "order_source" => 9,
  807. "platform_id" => $param['platform_id'],
  808. "good_code" => $goodCode,
  809. "skuCode" => '',
  810. "cat_id" => $param['cat_id'],
  811. "good_name" => $param['goodName'],
  812. "good_num" => $param['goodNum'],
  813. "good_type" => 1,
  814. "origin_price" => $cgdprice,
  815. "sale_price" => $saleprice,
  816. "total_price" =>$param['sale_total'],
  817. "post_fee" => 0,
  818. "is_diff" => 0,
  819. "is_activity" => 0,
  820. "activity_code" => '',
  821. "is_stock" => 0,
  822. "arrive_time" => $param['sendtime'],
  823. "customer_code" => $param['khNo'],
  824. "customerName" => $tmp['data'][$param['khNo']],
  825. "supplierNo" => $param['companyNo'],
  826. "supplierName" =>$tmp['data'][$param['companyNo']],
  827. "supName" => $tmp['data'][$param['supplierNo']],
  828. "supNo" => $param['supplierNo'],
  829. "platform_order" => $param['poCode'],
  830. "send_num" => $param['goodNum'],
  831. "wsend_num" => 0,
  832. "send_status" => 3,
  833. "send_type" => 1,
  834. "status" => 2,
  835. "is_del" => 0,
  836. "pay_id" => 0,
  837. "workNo" => $param['workCode'],
  838. "addtime" => date("Y-m-d H:i:s"),
  839. "updatetime" => date("Y-m-d H:i:s"),
  840. "cgderid" => $person['personid'],
  841. "cgder" => $person['person'],
  842. "good_createrid" => $this->uid,
  843. "good_creater" => $this->uname
  844. ];
  845. $orderCgd = [
  846. "orderCode" => $qrdcode,
  847. "cgdNo" => $cgddcode,
  848. "spuCode" => $goodCode,
  849. "good_num" => $param['goodNum'],
  850. "wsend_num" => 0,
  851. "send_num" => $param['goodNum'],
  852. "wait_num" => 0
  853. ];
  854. $cgddata = [
  855. "cgdNo" => $cgddcode,
  856. "bkcode" => '',
  857. "wsm_code" => "",
  858. "cgder_id" => $person['personid'],
  859. 'cgder' => $person['person'],
  860. "spuCode" => $goodCode,
  861. "good_name" => $param['goodName'],
  862. "good_num" => $param['goodNum'],
  863. "good_price" => $cgdprice,
  864. "total_fee" => $param['cgd_total'],
  865. "supplierNo" => $param['supplierNo'],
  866. "supplier_name" =>$tmp['data'][$param['supplierNo']],
  867. "companyNo" => $param['companyNo'],
  868. "companyName" => $tmp['data'][$param['companyNo']],
  869. "send_status" => 3,
  870. "send_num" => $param['goodNum'],
  871. "wsend_num" => 0,
  872. "status" => 3,
  873. "lasttime" => date("Y-m-d H:i:s"),
  874. "order_type" => $param['qrdType'],
  875. "order_source" => 9,
  876. "addtime" => date("Y-m-d H:i:s"),
  877. "updatetime" => date("Y-m-d H:i:s"),
  878. "good_createrid" => $this->uid,
  879. "good_creater" => $this->uname,
  880. ];
  881. $goodinfo = [
  882. "spuCode" => $goodCode,
  883. "good_name" => $param['goodName'],
  884. "brand_id" => 0,
  885. "cat_id" => $param['cat_id'],
  886. "good_unit" => $param['goodUnit'],
  887. "good_type" => 1,
  888. "moq" => 1,
  889. "customized" => 0,
  890. "platform_id" => $param['platform_id'],
  891. "tax" => $param['tax'],
  892. "supplierNo" => $param['supplierNo'],
  893. "supplierName" =>$tmp['data'][$param['supplierNo']],
  894. "is_auth" => 1,
  895. "craft_desc" => '',
  896. "good_remark" => '',
  897. "good_img" => '',
  898. "good_thumb_img" => '',
  899. "good_info_img" => '',
  900. "createrid" => $this->uid,
  901. "creater" => $this->uname,
  902. "specinfo" => '',
  903. "work_day" => 0,
  904. "noble_metal" => 0,
  905. "good_weight" => 0,
  906. "config" => "",
  907. "weight" => 0,
  908. "supply_area" => 0,
  909. "is_diff" => 0,
  910. "pay_way" => 0,
  911. "send_way" => 0,
  912. "companyNo" => $param['companyNo'],
  913. "companyName" => $tmp['data'][$param['companyNo']],
  914. "addtime" => date("Y-m-d H:i:s"),
  915. "updatetime" => date("Y-m-d H:i:s"),
  916. ];
  917. $orderAddr = [
  918. "orderCode" => $qrdcode,
  919. "addr" => $param['addr'],
  920. "addr_code" => $param['addr_code'],
  921. "contactor" => $param['contactor'],
  922. "mobile" => $param['mobile'],
  923. "arrive_time" => $param['sendtime'],
  924. "customer_code" => $param['khNo'],
  925. "receipt_quantity" => $param['goodNum'],
  926. "addtime" => date("Y-m-d H:i:s"),
  927. "updatetime" => date("Y-m-d H:i:s"),
  928. ];
  929. Db::startTrans();
  930. try {
  931. $qrd = Db::name("sale")->insert($qrddata);
  932. if ($qrd == false) throw new Exception("销售单生成失败");
  933. $qrd = Db::name("order_num")->insert($orderCgd);
  934. if ($qrd == false) throw new Exception("销售单采购管联生成失败");
  935. $qrd = Db::name("purchease_order")->insert($cgddata);
  936. if ($qrd == false) throw new Exception("采购单生成失败");
  937. $qrd = Db::name("good_zixun")->insert($goodinfo);
  938. if ($qrd == false) throw new Exception("商品信息录入生成失败");
  939. $qrd = Db::name("order_addr")->insert($orderAddr);
  940. if ($qrd == false) throw new Exception("销售单地址生成失败");
  941. Db::commit();
  942. return app_show(0, '订单生成成功');
  943. } catch (\Exception $exception) {
  944. Db::rollback();
  945. return error_show(1004, $exception->getMessage());
  946. }
  947. }
  948. public function orderInfo()
  949. {
  950. $param = $this->request->param(["orderCode"], "post", "trim");
  951. if ($param['orderCode'] == '') return error_show(1004, "订单编号不能为空");
  952. $saleinfo = Db::name("sale")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  953. if (empty($saleinfo)) return error_show(1004, "销售单不存在");
  954. if ($saleinfo['order_source'] != 9) return error_show(1004, "销售单来源不是网络录入");
  955. $cgd = Db::name("purchease_order")->alias("a")
  956. ->leftJoin("order_num b", "a.cgdNo=b.cgdNo")
  957. ->where(["b.orderCode" => $param['orderCode']])
  958. ->field("a.*")
  959. ->findOrEmpty();
  960. if (empty($cgd)) return error_show(1004, "采购单不存在");
  961. $goodinfo = Db::name("good_zixun")->where(["spuCode" => $saleinfo['good_code']])->findOrEmpty();
  962. if (empty($goodinfo)) return error_show(1004, "商品信息不存在");
  963. $addr = Db::name("order_addr")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  964. if (empty($addr)) return error_show(1004, "地址信息不存在");
  965. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  966. if (is_string($addinfo) && $addinfo != '') {
  967. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  968. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  969. }
  970. $platform = Db::name("platform")->where(["id" => $saleinfo['platform_id']])->field("platform_name,pay_title")
  971. ->findOrEmpty();
  972. $userCommon =\app\admin\common\User::getIns();
  973. $names = $userCommon->handle('getCodeAndName', ['code' => [$saleinfo['supplierNo'], $saleinfo['customer_code']]]);
  974. $data = [
  975. "orderCode" => $saleinfo['orderCode'],
  976. "companyNo" => $saleinfo['supplierNo'],
  977. "companyName" => $names['data'][$saleinfo['supplierNo']] ?? '',//Db::name("supplier")->where(["code" => $saleinfo['supplierNo']])->value("name", ''),
  978. "poCode" => $saleinfo['platform_order'],
  979. "workCode" => $saleinfo['workNo'],
  980. "platform_id" => $saleinfo['platform_id'],
  981. "platform_name" =>$platform['platform_name']??"",
  982. "khNo" => $saleinfo['customer_code'],
  983. "khName" => $names['data'][$saleinfo['customer_code']] ?? '',//Db::name("customer_info")->where(["companyNo" => $saleinfo['customer_code']])->value("companyName", ''),
  984. "qrdType" => $saleinfo['order_type'],
  985. "goodName" => $saleinfo['good_name'],
  986. "tax" => $goodinfo['tax'],
  987. "goodUnit" => $goodinfo['good_unit'],
  988. "unitName" => Db::name("unit")->where(["id" => $goodinfo['good_unit']])->value("unit", ""),
  989. "goodNum" => $saleinfo['good_num'],
  990. "goodPrice" => $saleinfo['sale_price'],
  991. "sale_total" => $saleinfo['total_price'],
  992. "mobile" => $addr['mobile'],
  993. "addr" => $addr['addr'],
  994. "addr_cn" => GetAddr(json_encode($addinfo)),
  995. "addr_code" => $addr['addr_code'],
  996. "contactor" => $addr['contactor'],
  997. "buyerid" => $saleinfo['cgderid'],
  998. "buyer_name" => $saleinfo['cgder'],
  999. "sendtime" => $saleinfo['arrive_time'],
  1000. "cat_id" => made($saleinfo['cat_id']),
  1001. "cat_name" => Db::name("cat")->where(["id" => $saleinfo['cat_id']])->value("cat_name", ''),
  1002. "supplierNo" => $cgd['supplierNo'],
  1003. "supplierNanme" => $cgd['supplier_name'],
  1004. "cgd_tax" => round((1 - $cgd['total_fee']/ $saleinfo['total_price']), 4) * 100,
  1005. "cgdPrice" => $saleinfo['origin_price'],
  1006. "cgd_total" => $cgd['total_fee'],
  1007. "pay_id" => $saleinfo['pay_id'],
  1008. "pay_name" =>$platform['pay_title']??"",
  1009. ];
  1010. return app_show(0, "获取成功", $data);
  1011. }
  1012. public function orderEdit()
  1013. {
  1014. $param = $this->request->param([
  1015. "orderCode" => "",
  1016. "poCode" => "",
  1017. "workCode" => "",
  1018. "tax" => "",
  1019. "goodUnit" => "",
  1020. "mobile" => "",
  1021. "addr" => "",
  1022. "addr_code" => "",
  1023. "contactor" => "",
  1024. "sendtime" => "",
  1025. "supplierNo" => "",
  1026. "cgd_total" => "",
  1027. // "sale_total" => "",
  1028. ], "post", "trim");
  1029. $valid = Validate::rule([
  1030. "orderCode|销售单号" => "require|max:255",
  1031. "supplierNo|供应商公司编号" => "require|max:255|min:1",
  1032. "poCode|PO编号" => "require|max:255|min:1",
  1033. "mobile|联系人电话" => "require|number|mobile",
  1034. "goodUnit|商品单位" => "require|number|gt:0",
  1035. "contactor|联系人" => "require|max:255|min:1",
  1036. "addr|收货地址" => "require|max:255|min:1",
  1037. "sendtime|发货时间" => "require|date",
  1038. "tax|商品利率" => "require|number",
  1039. "cgd_total|采购总额" => "require|float|gt:0",
  1040. // "sale_total|销售总额" => "require|float|gt:0",
  1041. ]);
  1042. if ($valid->check($param) == false) return error_show(1004, $valid->getError());
  1043. $saleinfo = Db::name("sale")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  1044. if (empty($saleinfo)) return error_show(1004, "销售单不存在");
  1045. if ($saleinfo['order_source'] != 9) return error_show(1004, "销售单来源不是网络录入");
  1046. $cgd = Db::name("purchease_order")->alias("a")
  1047. ->leftJoin("order_num b", "a.cgdNo=b.cgdNo")
  1048. ->where(["b.orderCode" => $param['orderCode']])
  1049. ->field("a.*")
  1050. ->findOrEmpty();
  1051. if (empty($cgd)) return error_show(1004, "采购单不存在");
  1052. $userCommon = \app\admin\common\User::getIns();
  1053. $good = Db::name("good_zixun")->where(["spuCode" => $saleinfo['good_code']])->findOrEmpty();
  1054. if (empty($good)) return error_show(1004, "商品信息不存在");
  1055. $addr = Db::name("order_addr")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  1056. if (empty($addr)) return error_show(1004, "地址信息不存在");
  1057. $cgdPrice = round($param['cgd_total']/$saleinfo['good_num'],2);
  1058. // $salePrice = round($param['sale_total']/$saleinfo['good_num'],2);
  1059. $supplierinfo = $userCommon->handle("hqInfo",["code"=>$param['supplierNo']]);
  1060. if(!isset($supplierinfo['data'])|| empty($supplierinfo['data'])) return json_show(1004, "未找到供应商公司数据");
  1061. $person =$supplierinfo['data']['child']??["person"=>'',"person_id"=>0];
  1062. if($cgd['companyNo']== $supplierinfo['data']['relation_code']) return json_show(1004,'供应商和业务公司不能为同一家公司');
  1063. $qrddata = [
  1064. "origin_price" => $cgdPrice,
  1065. "arrive_time" => $param['sendtime'],
  1066. "platform_order" => $param['poCode'],
  1067. "workNo" => $param['workCode'],
  1068. "updatetime" => date("Y-m-d H:i:s"),
  1069. "cgderid" => $person['personid'],
  1070. "cgder" => $person['person']
  1071. ];
  1072. $cgddata = [
  1073. "cgder_id" => $person['personid'],
  1074. 'cgder' => $person['person'],
  1075. "good_price" => $cgdPrice,
  1076. "total_fee" => $param['cgd_total'],
  1077. "supplierNo" => $param['supplierNo'],
  1078. "supplier_name" => $supplierinfo['data']['name'],
  1079. // "companyNo"=>$param['companyNo'],
  1080. "updatetime" => date("Y-m-d H:i:s"),
  1081. ];
  1082. $goodinfo = [
  1083. "good_unit" => $param['goodUnit'],
  1084. "tax" => $param['tax'],
  1085. "supplierNo" => $param['supplierNo'],
  1086. // "companyNo" => $param['companyNo'],
  1087. "updatetime" => date("Y-m-d H:i:s"),
  1088. ];
  1089. $orderAddr = [
  1090. "addr" => $param['addr'],
  1091. "addr_code" => $param['addr_code'],
  1092. "contactor" => $param['contactor'],
  1093. "mobile" => $param['mobile'],
  1094. "arrive_time" => $param['sendtime'],
  1095. // "customer_code" => $param['khNo'],
  1096. "updatetime" => date("Y-m-d H:i:s"),
  1097. ];
  1098. Db::startTrans();
  1099. try {
  1100. $qrd = Db::name("sale")->where($saleinfo)->update($qrddata);
  1101. if ($qrd == false) throw new Exception("销售单更新失败");
  1102. $qrd = Db::name("purchease_order")->where($cgd)->update($cgddata);
  1103. if ($qrd == false) throw new Exception("采购单更新失败");
  1104. $qrd = Db::name("good_zixun")->where($good)->update($goodinfo);
  1105. if ($qrd == false) throw new Exception("商品信息更新失败");
  1106. $qrd = Db::name("order_addr")->where($addr)->update($orderAddr);
  1107. if ($qrd == false) throw new Exception("销售单地址更新失败");
  1108. Db::commit();
  1109. return app_show(0, '订单更新成功');
  1110. } catch (\Exception $exception) {
  1111. Db::rollback();
  1112. return error_show(1004, $exception->getMessage());
  1113. }
  1114. }
  1115. }