Filing.php 56 KB

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