Filing.php 61 KB

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