Goodup.php 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\Exception;
  8. use think\facade\Db;
  9. use think\facade\Validate;
  10. //商品基础库
  11. class Goodup extends Base
  12. {
  13. public $noble=[];
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->noble=\think\facade\Config::get("noble");
  18. }
  19. public function list(){
  20. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  21. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  22. $where =[["is_del","=",0]];
  23. $condit =[["a.is_del","=",0]];
  24. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  25. if($cat_id!==""){
  26. $cat_ids=catChild($cat_id);
  27. $where[]=['cat_id',"in",$cat_ids];
  28. $condit[]=['a.cat_id',"in",$cat_ids];
  29. }
  30. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  31. if($good_name!==""){
  32. $where[]=['good_name',"like","%$good_name%"];
  33. $condit[]=['a.good_name',"like","%$good_name%"];
  34. }
  35. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  36. :"";
  37. if($spucode!==""){
  38. $where[]=['spuCode',"like","%$spucode%"];
  39. $condit[]=['a.spuCode',"like","%$spucode%"];
  40. }
  41. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type'])
  42. :"";
  43. if($good_type!==""){
  44. $where[]=['good_type',"=",$good_type];
  45. $condit[]=['a.good_type',"=",$good_type];
  46. }
  47. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo'])
  48. :"";
  49. if($companyNo!==""){
  50. $where[]=['companyNo',"like","%$companyNo%"];
  51. $condit[]=['a.companyNo',"like","%$companyNo%"];
  52. }
  53. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  54. :"";
  55. if($supplierNo!==""){
  56. $where[]=['supplierNo',"like","%$supplierNo%"];
  57. $condit[]=['a.supplierNo',"like","%$supplierNo%"];
  58. }
  59. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier'])
  60. :"";
  61. if($supplier!==""){
  62. $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  63. $where[]=['supplierNo',"in",$suppliernos];
  64. $condit[]=['a.supplierNo',"in",$suppliernos];
  65. }
  66. $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company'])
  67. :"";
  68. if($company!==""){
  69. $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  70. $where[]=['companyNo',"in",$companyNos];
  71. $condit[]=['a.companyNo',"in",$companyNos];
  72. }
  73. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
  74. :"";
  75. if($brandid!==""){
  76. $where[]=['brand_id',"=",$brandid];
  77. $condit[]=['a.brand_id',"=",$brandid];
  78. }
  79. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  80. :"";
  81. if($status!==""){
  82. $where[]=['status',"=",$status];
  83. $condit[]=['a.status',"=",$status];
  84. }
  85. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  86. if ($is_stock!=='') {
  87. $where[] = ['is_stock', "=", $is_stock];
  88. }
  89. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  90. if($start!==""){
  91. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  92. $condit[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  93. }
  94. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  95. if($end!==""){
  96. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  97. $condit[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  98. }
  99. $isonline = isset($this->post['isonline']) && $this->post['isonline']!=="" ? $this->post['isonline']:"";
  100. if($isonline!==""){
  101. if($isonline==1){
  102. $condit[] =['b.exam_status',"=",6];
  103. }else{
  104. $condit[] =['b.exam_status',"<>",6];
  105. }
  106. $sta =Db::name("good_basic")->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($condit)
  107. ->group("a.spuCode")->column('a.spuCode');
  108. $where[]=["spuCode","in",$sta];
  109. }
  110. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  111. if($token==""){
  112. return error_show(101,'token不能为空');
  113. }
  114. $apply_id =GetUserInfo($token);
  115. if(empty($apply_id)||$apply_id['code']!=0){
  116. return error_show(102,"申请人数据不存在");
  117. }
  118. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  119. if($rm!=''){
  120. $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find();
  121. if($useinfo==false){
  122. return error_show(1002,"未找到用户角色权限");
  123. }
  124. $check = checkRole($useinfo['roleid'],115);
  125. if($check){
  126. $where[]=['createrid', "=" ,$rm];
  127. }
  128. }
  129. $count = Db::name('good_basic')->where($where)->count();
  130. $total = ceil($count / $size);
  131. $page = $page >= $total ? $total : $page;
  132. $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select()->toArray();
  133. $data=[];
  134. //查询一下这些spucode是否在平台上成功上线
  135. $exam_statuss = Db::name('good_platform')
  136. ->whereIn('spuCode',array_column($list,'spuCode'))
  137. ->where(['is_del'=>0,'exam_status'=>6])//exam_status==6表示上线审核成功
  138. ->column('id','spuCode');
  139. foreach ($list as $value){
  140. $value["cat_info"]= made($value['cat_id'],[]);
  141. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  142. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  143. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  144. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  145. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  146. $value['company'] = isset($company['company'])?$company['company']:"";
  147. $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  148. $value['supplier_name']=isset($supplier['name'])?$supplier['name']:"";
  149. $value['exclusive']=makeExcluse($value['is_exclusive']);
  150. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  151. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  152. if (!empty($exam_statuss) && isset($exam_statuss[$value['spuCode']])) {
  153. $value['is_online'] = 1;
  154. }
  155. $data[]=$value;
  156. }
  157. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  158. }
  159. public function create(){
  160. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  161. if($good_name==""){
  162. return error_show(1004,"商品名称不能为空");
  163. }
  164. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  165. if($cat_id==''){
  166. return error_show(1004,"商品分类不能为空");
  167. }
  168. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  169. if($brandid==''){
  170. return error_show(1004,"商品品牌不能为空");
  171. }
  172. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  173. if($unit==''){
  174. return error_show(1004,"商品单位不能为空");
  175. }
  176. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  177. :"";
  178. if($good_type===''){
  179. return error_show(1004,"参数good_type不能为空");
  180. }
  181. $moq=0;
  182. $customized=0;
  183. if($good_type==1){
  184. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  185. if($moq===''){
  186. return error_show(1004,"定制商品起订量不能为空");
  187. }
  188. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  189. if($customized===''){
  190. return error_show(1004,"参数customized不能为空");
  191. }
  192. }
  193. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  194. if($is_exclusive===''){
  195. return error_show(1004,"参数is_exclusive不能为空");
  196. }
  197. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  198. // if($customized===''){
  199. // return error_show(1004,"参数customized不能为空");
  200. // }
  201. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  202. if($tax===''){
  203. return error_show(1004,"参数tax不能为空");
  204. }
  205. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  206. if($supplierNo==''){
  207. return error_show(1004,"参数supplierNo不能为空");
  208. }
  209. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  210. if($good_size==''){
  211. return error_show(1004,"参数good_size不能为空");
  212. }
  213. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  214. :"";
  215. if($company_id==''){
  216. return error_show(1004,"参数company_id不能为空");
  217. }
  218. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  219. if($is_auth===''){
  220. return error_show(1004,"参数is_auth不能为空");
  221. }
  222. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  223. // if($auth_img==''){
  224. // return error_show(1004,"商品不能为空");
  225. // }
  226. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  227. if($after_sales==""){
  228. return error_show(1004,"参数after_sales不能为空");
  229. }
  230. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  231. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  232. if($good_remark===""){
  233. return error_show(1004,"参数good_remark不能为空");
  234. }
  235. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  236. if($weight===""){
  237. return error_show(1004,"参数weight不能为空");
  238. }
  239. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  240. if($packing_way===""){
  241. return error_show(1004,"参数packing_way不能为空");
  242. }
  243. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  244. if($packing_size===""){
  245. return error_show(1004,"参数packing_size不能为空");
  246. }
  247. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  248. if($packing_spec===""){
  249. return error_show(1004,"参数packing_spec不能为空");
  250. }
  251. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  252. if($packing_weight===""){
  253. return error_show(1004,"参数packing_weight不能为空");
  254. }
  255. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  256. if($packing_list===""){
  257. return error_show(1004,"参数packing_list不能为空");
  258. }
  259. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  260. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  261. if($supply_area===""){
  262. return error_show(1004,"参数supply_area不能为空");
  263. }
  264. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  265. if($delivery_place===""){
  266. return error_show(1004,"参数delivery_place不能为空");
  267. }
  268. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  269. if($origin_place===""){
  270. return error_show(1004,"参数origin_place不能为空");
  271. }
  272. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  273. if($delivery_day===""){
  274. return error_show(1004,"参数delivery_day不能为空");
  275. }
  276. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  277. :"0";
  278. $cgd_gold_price =isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""?floatval($this->post['cgd_gold_price']):"0";
  279. // if($lead_time===""){
  280. // return error_show(1004,"参数lead_time不能为空");
  281. // }
  282. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  283. // if($sample_day===""){
  284. // return error_show(1004,"参数sample_day不能为空");
  285. // }
  286. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  287. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  288. if($is_stock===""){
  289. return error_show(1004,"参数is_stock不能为空");
  290. }
  291. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  292. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  293. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  294. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  295. if($good_img===""){
  296. return error_show(1004,"参数good_img不能为空");
  297. }
  298. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  299. if($good_thumb_img===""){
  300. return error_show(1004,"参数good_thumb_img不能为空");
  301. }
  302. $good_info_img = isset($this->post['good_info_img'])&&$this->post['good_info_img']!=""? trim($this->post['good_info_img']):"";
  303. if($good_info_img===""){
  304. return error_show(1004,"参数good_info_img不能为空");
  305. }
  306. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  307. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  308. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  309. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  310. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  311. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  312. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  313. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  314. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  315. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  316. if($market_price===""){
  317. return error_show(1004,"参数market_price不能为空");
  318. }
  319. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  320. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  321. // if($is_step===""){
  322. // return error_show(1004,"参数is_step不能为空");
  323. // }
  324. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  325. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  326. // if($is_step==1 && $good_ladder==""){
  327. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  328. // }
  329. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  330. if($token==''){
  331. return error_show(105,"参数token不能为空");
  332. }
  333. $user =GetUserInfo($token);
  334. if(empty($user)||$user['code']!=0){
  335. return error_show(1002,"创建人数据不存在");
  336. }
  337. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  338. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  339. $spucode=makeNo("SKU");
  340. Db::startTrans();
  341. try {
  342. $data=[
  343. "spuCode"=>$spucode,
  344. "good_code"=>'',
  345. "good_name"=>$good_name,
  346. "cat_id"=>$cat_id,
  347. 'brand_id'=>$brandid,
  348. "good_unit"=>$unit,
  349. "good_type"=>$good_type,
  350. "moq"=>$moq,
  351. "is_exclusive"=>$is_exclusive,
  352. "customized"=>$customized,
  353. "companyNo"=>$company_id,
  354. "tax"=>$tax,
  355. "supplierNo"=>$supplierNo,
  356. "good_size"=>$good_size,
  357. "is_auth"=>$is_auth,
  358. "is_stock"=>$is_stock,
  359. "auth_img"=>$auth_img,
  360. "after_sales"=>$after_sales,
  361. "craft_desc"=>$craft_desc,
  362. "good_remark"=>$good_remark,
  363. "weight"=>$weight,
  364. "packing_way"=>$packing_way,
  365. "packing_size"=>$packing_size,
  366. "packing_spec"=>$packing_spec,
  367. "packing_list"=>$packing_list,
  368. "packing_weight"=>$packing_weight,
  369. "good_bar"=>$good_bar,
  370. "supply_area"=>$supply_area,
  371. "delivery_place"=>$delivery_place,
  372. "origin_place"=>$origin_place,
  373. "delivery_day"=>$delivery_day,
  374. "lead_time"=>$lead_time,
  375. "sample_day"=>$sample_day,
  376. "sample_fee"=>$sample_fee,
  377. "good_img"=>$good_img,
  378. "good_thumb_img"=>$good_thumb_img,
  379. "good_info_img"=>$good_info_img,
  380. "cert_fee"=>$cert_fee,
  381. "packing_fee"=>$packing_fee,
  382. "cost_fee"=>$cost_fee,
  383. "mark_fee"=>$mark_fee,
  384. "demo_fee"=>$demo_fee,
  385. "open_fee"=>$open_fee,
  386. "noble_metal"=>$noble_metal,
  387. "cgd_gold_price"=>$cgd_gold_price,
  388. "noble_weight"=>$noble_weight,
  389. "is_gold_price"=>$is_gold_price,
  390. "market_price"=>$market_price,
  391. "nake_price"=>$nake_price,
  392. "is_diff"=>$is_diff,
  393. "config"=>$config,
  394. "other_config"=>$other_config,
  395. "field_change"=>'',
  396. "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
  397. "is_online"=>0,
  398. "status"=>0,
  399. "createrid"=>$createrid,
  400. "creater"=>$creater,
  401. "addtime"=>date("Y-m-d H:i:s"),
  402. "updatetime"=>date("Y-m-d H:i:s")
  403. ];
  404. $in = Db::name("good_basic")->insert($data);
  405. if($in){
  406. if($speclist!=="" && !empty($speclist)){
  407. $temp=[];
  408. foreach ($speclist as $value){
  409. $lemp=[];
  410. $lemp['spuCode']=$spucode;
  411. $lemp['spec_id'] = $value['spec_id'];
  412. $lemp['spec_value_id'] = $value['spec_value_id'];
  413. $lemp['addtime'] = date("Y-m-d H:i:s");
  414. $lemp['updatetime'] =date("Y-m-d H:i:s");
  415. $temp[]=$lemp;
  416. }
  417. $count = Db::name("good_spec")->insertAll($temp);
  418. if($count==0){
  419. Db::rollback();
  420. return app_show(1004,"商品规格值创建失败");
  421. }
  422. }
  423. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  424. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  425. $top_cat_id = made($cat_id);//获取所有分类
  426. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  427. if($good_ladder!=="" && !empty($good_ladder)){
  428. $temp=[];
  429. foreach ($good_ladder as $value){
  430. $lemp=[];
  431. $lemp['spuCode']=$spucode;
  432. $lemp['min_num'] = $value['min_num'];
  433. $lemp['nake_fee'] = $value['nake_fee'];
  434. $lemp['cost_fee'] = $value['cost_fee'];
  435. $lemp['delivery_fee'] = $value['delivery_fee'];
  436. $lemp['cert_fee'] = $value['cert_fee'];
  437. $lemp['mark_fee'] = $value['mark_fee'];
  438. $lemp['package_fee'] = $value['package_fee'];
  439. $lemp['other_fee'] = $value['other_fee'];
  440. if($is_gold_price==1 && $top_cat_id==6){
  441. //$is_gold_price==1 表示启用实时金价,cat_id==6表示贵金属
  442. $gold = Db::name("gold_price1")->where(["type" => $noble_metal, "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  443. //$lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  444. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  445. //成本总计启用实时金价时,采用供应商实时金价
  446. $lemp['nake_total'] = $noble_weight *$gold['price'] + $value['cost_fee'] * $noble_weight +
  447. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  448. }else{
  449. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  450. }
  451. $lemp['creater_id'] = $createrid;
  452. $lemp['creater'] = $creater;
  453. $lemp['is_del'] = 0;
  454. $lemp['addtime'] = date("Y-m-d H:i:s");
  455. $lemp['updatetime'] =date("Y-m-d H:i:s");
  456. $temp[]=$lemp;
  457. }
  458. $count = Db::name("good_nake")->insertAll($temp);
  459. if($count==0){
  460. Db::rollback();
  461. return app_show(1004,"商品规格值创建失败");
  462. }
  463. }
  464. //修改状态,添加待办
  465. ActionLog::logAdd($this->post['token'], [
  466. "order_code" =>$spucode,//咨询单详情编号
  467. "status" => 0,//这里的status是之前的值
  468. "action_remark" => '',//备注
  469. "action_type" => "create"//新建create,编辑edit,更改状态status
  470. ], "SPCB", 0,$data);
  471. ProcessOrder::AddProcess($this->post['token'], [
  472. "order_type" => 'SPCB',
  473. "order_code" => $spucode,//咨询单详情编号
  474. "order_id" => Db::name("good_basic")->getLastInsID(),
  475. "order_status" =>0
  476. ]);
  477. Db::commit();
  478. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  479. }else{
  480. Db::rollback();
  481. return app_show(1004,"商品创建失败");
  482. }
  483. }catch (\Exception $e){
  484. Db::rollback();
  485. return app_show(1004,$e->getMessage());
  486. }
  487. }
  488. public function editinfo(){
  489. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  490. if($supcode==""){
  491. return error_show(1004,"参数spuCode不能为空");
  492. }
  493. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  494. if($data==false){
  495. return error_show(1004,"未找到商品数据");
  496. }
  497. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  498. if($good_name==""){
  499. return error_show(1004,"商品名称不能为空");
  500. }
  501. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  502. if($cat_id==''){
  503. return error_show(1004,"商品分类不能为空");
  504. }
  505. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  506. // if($brandid==''){
  507. // return error_show(1004,"商品品牌不能为空");
  508. // }
  509. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  510. if($unit==''){
  511. return error_show(1004,"商品单位不能为空");
  512. }
  513. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  514. :"";
  515. if($good_type===''){
  516. return error_show(1004,"参数good_type不能为空");
  517. }
  518. $moq=0;
  519. $customized=0;
  520. if($good_type==1){
  521. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  522. if($moq===''){
  523. return error_show(1004,"定制商品起订量不能为空");
  524. }
  525. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  526. if($customized===''){
  527. return error_show(1004,"参数customized不能为空");
  528. }
  529. }
  530. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  531. if($is_exclusive===''){
  532. return error_show(1004,"参数is_exclusive不能为空");
  533. }
  534. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  535. // if($customized===''){
  536. // return error_show(1004,"参数customized不能为空");
  537. // }
  538. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  539. if($tax===''){
  540. return error_show(1004,"参数tax不能为空");
  541. }
  542. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  543. if($supplierNo==''){
  544. return error_show(1004,"参数supplierNo不能为空");
  545. }
  546. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  547. :"";
  548. if($good_size==''){
  549. return error_show(1004,"参数good_size不能为空");
  550. }
  551. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  552. :"";
  553. if($company_id==''){
  554. return error_show(1004,"参数company_id不能为空");
  555. }
  556. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  557. if($is_auth===''){
  558. return error_show(1004,"参数is_auth不能为空");
  559. }
  560. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  561. // if($auth_img==''){
  562. // return error_show(1004,"商品不能为空");
  563. // }
  564. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  565. if($after_sales==""){
  566. return error_show(1004,"参数after_sales不能为空");
  567. }
  568. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  569. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  570. if($good_remark===""){
  571. return error_show(1004,"参数good_remark不能为空");
  572. }
  573. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  574. if($weight===""){
  575. return error_show(1004,"参数weight不能为空");
  576. }
  577. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  578. if($packing_way===""){
  579. return error_show(1004,"参数packing_way不能为空");
  580. }
  581. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  582. if($packing_size===""){
  583. return error_show(1004,"参数packing_size不能为空");
  584. }
  585. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  586. if($packing_spec===""){
  587. return error_show(1004,"参数packing_spec不能为空");
  588. }
  589. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  590. if($packing_weight===""){
  591. return error_show(1004,"参数packing_weight不能为空");
  592. }
  593. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  594. if($packing_list===""){
  595. return error_show(1004,"参数packing_list不能为空");
  596. }
  597. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  598. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  599. if($supply_area===""){
  600. return error_show(1004,"参数supply_area不能为空");
  601. }
  602. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  603. if($delivery_place===""){
  604. return error_show(1004,"参数delivery_place不能为空");
  605. }
  606. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  607. if($origin_place===""){
  608. return error_show(1004,"参数origin_place不能为空");
  609. }
  610. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  611. if($delivery_day===""){
  612. return error_show(1004,"参数delivery_day不能为空");
  613. }
  614. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  615. :"0";
  616. // if($lead_time===""){
  617. // return error_show(1004,"参数lead_time不能为空");
  618. // }
  619. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  620. // if($sample_day===""){
  621. // return error_show(1004,"参数sample_day不能为空");
  622. // }
  623. // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval
  624. //($this->post['sample_fee']):"0";
  625. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  626. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  627. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  628. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  629. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  630. if($good_img===""){
  631. return error_show(1004,"参数good_img不能为空");
  632. }
  633. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  634. if($good_thumb_img===""){
  635. return error_show(1004,"参数good_thumb_img不能为空");
  636. }
  637. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  638. if($good_info_img===""){
  639. return error_show(1004,"参数good_info_img不能为空");
  640. }
  641. $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count();
  642. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  643. Db::startTrans();
  644. try {
  645. $temp=[
  646. "good_name"=>$good_name,
  647. "cat_id"=>$cat_id,
  648. 'brand_id'=>$brandid,
  649. "good_unit"=>$unit,
  650. "good_type"=>$good_type,
  651. "companyNo"=>$company_id,
  652. "moq"=>$moq,
  653. "is_exclusive"=>$is_exclusive,
  654. "customized"=>$customized,
  655. "tax"=>$tax,
  656. "supplierNo"=>$supplierNo,
  657. "is_auth"=>$is_auth,
  658. "good_size"=>$good_size,
  659. "auth_img"=>$auth_img,
  660. "after_sales"=>$after_sales,
  661. "craft_desc"=>$craft_desc,
  662. "good_remark"=>$good_remark,
  663. "weight"=>$weight,
  664. "packing_way"=>$packing_way,
  665. "packing_size"=>$packing_size,
  666. "packing_spec"=>$packing_spec,
  667. "packing_list"=>$packing_list,
  668. "packing_weight"=>$packing_weight,
  669. "good_bar"=>$good_bar,
  670. "supply_area"=>$supply_area,
  671. "delivery_place"=>$delivery_place,
  672. "origin_place"=>$origin_place,
  673. "delivery_day"=>$delivery_day,
  674. "lead_time"=>$lead_time,
  675. "sample_day"=>$sample_day,
  676. "is_diff"=>$is_diff,
  677. 'is_stock'=>$is_stock,
  678. "config"=>$config,
  679. "other_config"=>$other_config,
  680. "good_img"=>$good_img,
  681. "good_thumb_img"=>$good_thumb_img,
  682. "good_info_img"=>$good_info_img,
  683. "status"=>$count>0?2:1,
  684. "updatetime"=>date("Y-m-d H:i:s")
  685. ];
  686. $field = array_diff_assoc($temp,$data);
  687. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  688. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  689. $timp = array_diff($temp,$data);
  690. $json = json_encode($timp,JSON_UNESCAPED_UNICODE);
  691. $jsp = json_encode($data,JSON_UNESCAPED_UNICODE);
  692. if($up){
  693. ChangeLog::logAdd(3,$data['spuCode'],$jsp,$json,$this->post['token'],$this->post);
  694. if($speclist!=="" && !empty($speclist)){
  695. foreach ($speclist as $value){
  696. $lemp=[];
  697. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  698. $lemp['spuCode']=$supcode;
  699. $lemp['spec_id'] = $value['spec_id'];
  700. $lemp['spec_value_id'] = $value['spec_value_id'];
  701. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  702. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  703. $lemp['updatetime'] =date("Y-m-d H:i:s");
  704. $count = Db::name("good_spec")->save($lemp);
  705. if($count==false){
  706. Db::rollback();
  707. return app_show(1004,"商品规格值修改失败");
  708. }
  709. }
  710. }
  711. //修改状态,添加待办
  712. ActionLog::logAdd($this->post['token'], [
  713. "order_code" =>$supcode,//咨询单详情编号
  714. "status" => $data['status'],//这里的status是之前的值
  715. "action_remark" => '',//备注
  716. "action_type" => "edit"//新建create,编辑edit,更改状态status
  717. ], "SPCB",$temp['status'] ,$data);
  718. ProcessOrder::AddProcess($this->post['token'], [
  719. "order_type" => 'SPCB',
  720. "order_code" => $supcode,//咨询单详情编号
  721. "order_id" => $data['id'],
  722. "order_status" =>$temp['status']
  723. ]);
  724. Db::commit();
  725. return app_show(0,"更新成功");
  726. }else{
  727. Db::rollback();
  728. return error_show(1005,"更新失败");
  729. }
  730. }catch (\Exception $e){
  731. Db::rollback();
  732. return error_show(1004,$e->getMessage());
  733. }
  734. }
  735. public function editfee(){
  736. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  737. if($supcode==""){
  738. return error_show(1004,"参数spuCode不能为空");
  739. }
  740. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  741. if($datas==false){
  742. return error_show(1004,"未找到商品数据");
  743. }
  744. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  745. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  746. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  747. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  748. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  749. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  750. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  751. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  752. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  753. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  754. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  755. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  756. if($market_price===""){
  757. return error_show(1004,"参数market_price不能为空");
  758. }
  759. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  760. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  761. // if($is_step===""){
  762. // return error_show(1004,"参数is_step不能为空");
  763. // }
  764. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  765. // if($is_step==1 && $good_ladder==""){
  766. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  767. // }
  768. $data=[
  769. "cert_fee"=>$cert_fee,
  770. "packing_fee"=>$packing_fee,
  771. "cost_fee"=>$cost_fee,
  772. "mark_fee"=>$mark_fee,
  773. "demo_fee"=>$demo_fee,
  774. "open_fee"=>$open_fee,
  775. "sample_fee"=>$sample_fee,
  776. "noble_metal"=>$noble_metal,
  777. "noble_weight"=>$noble_weight,
  778. "is_gold_price"=>$is_gold_price,
  779. "market_price"=>$market_price,
  780. "nake_price"=>$nake_price,
  781. "cgd_gold_price"=>$cgd_gold_price,
  782. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  783. "status"=>"3",
  784. "updatetime"=>date("Y-m-d H:i:s")
  785. ];
  786. $field = array_diff_assoc($data,$datas);
  787. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  788. Db::startTrans();
  789. try{
  790. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  791. $temp = array_diff($data,$datas);
  792. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  793. $jsp = json_encode($datas,JSON_UNESCAPED_UNICODE);
  794. if($up){
  795. ChangeLog::logAdd(3,$datas['spuCode'],$jsp,$json,$this->post['token'],$this->post);
  796. //修改状态,添加待办
  797. ActionLog::logAdd($this->post['token'], [
  798. "order_code" =>$supcode,//咨询单详情编号
  799. "status" => $datas['status'],//这里的status是之前的值
  800. "action_remark" => '',//备注
  801. "action_type" => "edit"//新建create,编辑edit,更改状态status
  802. ], "SPCB",$data['status'] ,$data);
  803. ProcessOrder::AddProcess($this->post['token'], [
  804. "order_type" => 'SPCB',
  805. "order_code" => $supcode,//咨询单详情编号
  806. "order_id" => $datas['id'],
  807. "order_status" =>$data['status']
  808. ]);
  809. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  810. if($online){
  811. $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save
  812. (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  813. if($onup==false){
  814. Db::rollback();
  815. return app_show(1004,"商品规成本修改失败");
  816. }
  817. //修改状态,添加待办
  818. ActionLog::logAdd($this->post['token'], [
  819. "order_code" =>$online['skuCode'],//咨询单详情编号
  820. "status" => $online['exam_status'],//这里的status是之前的值
  821. "action_remark" => '',//备注
  822. "action_type" => "edit"//新建create,编辑edit,更改状态status
  823. ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  824. ProcessOrder::AddProcess($this->post['token'], [
  825. "order_type" => 'SPSX',
  826. "order_code" => $online['skuCode'],//咨询单详情编号
  827. "order_id" => $online['id'],
  828. "order_status" =>2
  829. ]);
  830. }
  831. if($good_ladder!=="" && !empty($good_ladder)){
  832. $user =GetUserInfo($this->post['token']);
  833. foreach ($good_ladder as $value){
  834. $lemp=[];
  835. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  836. $lemp['spuCode']=$supcode;
  837. $lemp['min_num'] = $value['min_num'];
  838. $lemp['nake_fee'] = $value['nake_fee'];
  839. $lemp['cost_fee'] = $value['cost_fee'];
  840. $lemp['delivery_fee'] = $value['delivery_fee'];
  841. $lemp['cert_fee'] = $value['cert_fee'];
  842. $lemp['mark_fee'] = $value['mark_fee'];
  843. $lemp['package_fee'] = $value['package_fee'];
  844. $lemp['other_fee'] = $value['other_fee'];
  845. if($is_gold_price==1 && $datas['cat_id']==6){
  846. //$gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  847. // ->order("addtime desc")->find();
  848. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  849. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  850. //成本总计启用实时金价时,采用供应商实时金价
  851. $lemp['nake_total'] = $noble_weight * $cgd_gold_price+ $value['cost_fee'] * $noble_weight +
  852. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  853. }else{
  854. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  855. }
  856. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  857. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  858. $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  859. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  860. $lemp['updatetime'] =date("Y-m-d H:i:s");
  861. $count = Db::name("good_nake")->save($lemp);
  862. if($count==false){
  863. Db::rollback();
  864. return app_show(1004,"商品规成本修改失败");
  865. }
  866. }
  867. }
  868. Db::commit();
  869. return app_show(0,"更新成功");
  870. }else{
  871. Db::rollback();
  872. return error_show(1005,"更新失败");
  873. }
  874. }catch (\Exception $e){
  875. Db::rollback();
  876. return error_show(1005,$e->getMessage());
  877. }
  878. }
  879. public function exam(){
  880. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  881. if($supcode==""){
  882. return error_show(1004,"参数spuCode不能为空");
  883. }
  884. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  885. if($data==false){
  886. return error_show(1004,"未找到商品数据");
  887. }
  888. if($data['status']==1){
  889. return error_show(1004,"商品已审核通过");
  890. }
  891. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  892. // if($status===""){
  893. // return error_show(1004,"参数status不能为空");
  894. // }
  895. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  896. // if($remark===""){
  897. // return error_show(1004,"参数remark不能为空");
  898. // }
  899. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  900. if($token==''){
  901. return error_show(105,"参数token不能为空");
  902. }
  903. $user =GetUserInfo($token);
  904. if(empty($user)||$user['code']!=0){
  905. return error_show(1002,"用户数据不存在");
  906. }
  907. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  908. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  909. Db::startTrans();
  910. try {
  911. if($data['status']==3 && $status==1){
  912. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  913. if($online) {
  914. $onl= Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->save(["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  915. if ($onl != false) {
  916. Db::rollback();
  917. return error_show(1004, "审核失败");
  918. }
  919. ActionLog::logAdd($this->post['token'], [
  920. "order_code" =>$online['skuCode'],//咨询单详情编号
  921. "status" => $online['exam_status'],//这里的status是之前的值
  922. "action_remark" => '',//备注
  923. "action_type" => "edit"//新建create,编辑edit,更改状态status
  924. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  925. ProcessOrder::AddProcess($this->post['token'], [
  926. "order_type" => 'SPSX',
  927. "order_code" =>$online['skuCode'],//咨询单详情编号
  928. "order_id" => $online['id'],
  929. "order_status" => 2
  930. ]);
  931. }
  932. }
  933. // if ($status == 1) {
  934. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  935. // Db::name('good')
  936. // ->where(['is_del' => 0, 'status' => 1])
  937. // ->whereIn('spuCode', $supcode)
  938. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  939. // }
  940. $data['status']=$status;
  941. $data['updatetime']=date("Y-m-d H:i:s");
  942. $up= Db::name("good_basic")->save($data);
  943. if($up){
  944. //修改状态,添加待办
  945. ActionLog::logAdd($this->post['token'], [
  946. "order_code" =>$supcode,//咨询单详情编号
  947. "status" => $status,//这里的status是之前的值
  948. "action_remark" => '',//备注
  949. "action_type" => "edit"//新建create,编辑edit,更改状态status
  950. ], "SPCB",$data['status'] ,$data);
  951. ProcessOrder::AddProcess($this->post['token'], [
  952. "order_type" => 'SPCB',
  953. "order_code" => $supcode,//咨询单详情编号
  954. "order_id" => $data['id'],
  955. "order_status" =>$data['status']
  956. ]);
  957. $data=[
  958. "code"=>$supcode,
  959. "exam_status"=>$status,
  960. "type"=>1,
  961. "exam_id"=>$createrid,
  962. "exam_name"=>$creater,
  963. "exam_remark"=>$remark,
  964. "addtime"=>date("Y-m-d H:i:s")
  965. ];
  966. $inr=Db::name("good_exam")->insert($data);
  967. if($inr){
  968. Db::commit();
  969. return app_show(0,"审核成功");
  970. }else{
  971. Db::rollback();
  972. return error_show(1004,"审核失败");
  973. }
  974. }else{
  975. Db::rollback();
  976. return error_show(1004,"审核失败");
  977. }
  978. }catch (\Exception $e){
  979. Db::rollback();
  980. return error_show(1004,$e->getMessage());
  981. }
  982. }
  983. public function info(){
  984. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  985. if($supcode==""){
  986. return error_show(1004,"参数spuCode不能为空");
  987. }
  988. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  989. if($data==false){
  990. return error_show(1004,"未找到商品数据");
  991. }
  992. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  993. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  994. $data['cat_info'] = made($data['cat_id'],[]);
  995. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  996. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  997. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  998. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  999. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1000. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  1001. $data['company'] = isset($company['company'])?$company['company']:"";
  1002. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1003. if($data['brand_id']!=0){
  1004. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1005. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1006. }else{
  1007. $data["brand_name"]="";
  1008. $data["brand_id"]="";
  1009. }
  1010. $excluse = makeExcluse($data['is_exclusive']);
  1011. $data['exclusive']=$excluse;
  1012. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1013. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1014. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1015. $gold=[];
  1016. if ($data['is_gold_price'] == 1) {
  1017. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1018. }
  1019. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1020. $speclist=[];
  1021. if(!empty($spec)){
  1022. foreach ($spec as $value){
  1023. $temp=[];
  1024. $temp['id']=$value['id'];
  1025. $temp['spuCode']=$value['spuCode'];
  1026. $temp['spec_id']=$value['spec_id'];
  1027. $temp['spec_value_id']=$value['spec_value_id'];
  1028. $temp['is_del']=$value['is_del'];
  1029. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1030. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1031. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1032. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1033. $speclist[]=$temp;
  1034. }
  1035. }
  1036. $data["speclist"]=empty($speclist)?[]:$speclist;
  1037. // $nake=[];
  1038. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1039. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1040. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1041. $nakearry=[];
  1042. if(!empty($nakelist)){
  1043. foreach ($nakelist as $value) {
  1044. $nakearry[] = $value;
  1045. }
  1046. }
  1047. $data["nakelist"]=$nakearry;
  1048. return app_show(0,"获取成功",$data);
  1049. }
  1050. public function delall(){
  1051. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1052. if($supcode==""){
  1053. return error_show(1004,"参数codes不能为空");
  1054. }
  1055. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1056. if(empty($data)){
  1057. return error_show(1004,"未找到商品数据");
  1058. }
  1059. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  1060. if($up){
  1061. ProcessOrder::workdel(["order_type"=>"CGD","order_code"=>$supcode]);
  1062. return app_show(0,"更新成功");
  1063. }else{
  1064. return error_show(1005,"更新失败");
  1065. }
  1066. }
  1067. //添加上线商品
  1068. public function online(){
  1069. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1070. if($platform==""){
  1071. return error_show(1004,"参数codes不能为空");
  1072. }
  1073. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1074. if($spuCode===''){
  1075. return error_show(1004,"参数codes不能为空");
  1076. }
  1077. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  1078. if(empty($datas)){
  1079. return error_show(1004,"未找到商品数据");
  1080. }
  1081. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1082. if($online_reason===""){
  1083. return error_show(1004,"参数online_reason不能为空");
  1084. }
  1085. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1086. if($online_remark===""){
  1087. return error_show(1004,"参数online_remark不能为空");
  1088. }
  1089. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1090. if($token==''){
  1091. return error_show(105,"参数token不能为空");
  1092. }
  1093. $user =GetUserInfo($token);
  1094. if(empty($user)||$user['code']!=0){
  1095. return error_show(1002,"用户数据不存在");
  1096. }
  1097. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1098. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1099. $data=[];
  1100. $isonline=[];
  1101. $i=0;
  1102. Db::startTrans();
  1103. try{
  1104. foreach ($datas as $value){
  1105. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1106. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1107. if($ist){
  1108. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1109. if($god){
  1110. $tp=[];
  1111. $tp['spuCode']=$value['spuCode'];
  1112. $tp['good_name']=$god['good_name'];
  1113. $tp['good_img']=$god['good_thumb_img'];
  1114. $tp['exam_status']=$ist['exam_status'];
  1115. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1116. $speclist=[];
  1117. if(!empty($spec)){
  1118. foreach ($spec as $val){
  1119. $temp=[];
  1120. $temp['id']=$val['id'];
  1121. $temp['spuCode']=$val['spuCode'];
  1122. $temp['spec_id']=$val['spec_id'];
  1123. $temp['spec_value_id']=$val['spec_value_id'];
  1124. $temp['is_del']=$val['is_del'];
  1125. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1126. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1127. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1128. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1129. $speclist[]=$temp;
  1130. }
  1131. }
  1132. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1133. $isonline[]=$tp;
  1134. }
  1135. }
  1136. if(!empty($isonline)){
  1137. return app_show(1009,"存在已上线产品",$isonline);
  1138. }
  1139. //改变编码规则,将原来的skuCode后两位换成序列号
  1140. //str_pad字符串填充
  1141. $skuCode = makeNo("SN");
  1142. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1143. $tmp=[
  1144. "spuCode"=>$value['spuCode'],
  1145. "skuCode"=>$skuCode,
  1146. "platform_code"=>$platform,
  1147. "online_reason"=>$online_reason,
  1148. "online_remark"=>$online_remark,
  1149. "exam_status"=>$count>0 ?2:1,
  1150. "is_online"=>0,
  1151. "status"=>1,
  1152. "is_del"=>0,
  1153. "creater"=>$creater,
  1154. "createrid"=>$createrid,
  1155. "addtime"=>date("Y-m-d H:i:s"),
  1156. "updatetime"=>date("Y-m-d H:i:s")
  1157. ];
  1158. $i++;
  1159. //修改状态,添加待办
  1160. $create =Db::name("good_platform")->insert($tmp,true);
  1161. if($create>0){
  1162. ActionLog::logAdd($this->post['token'], [
  1163. "order_code" =>$skuCode,//咨询单详情编号
  1164. "status" => $tmp['exam_status'],//这里的status是之前的值
  1165. "action_remark" => '',//备注
  1166. "action_type" => "create"//新建create,编辑edit,更改状态status
  1167. ], "SPSX",$tmp['exam_status'],$tmp);
  1168. ProcessOrder::AddProcess($this->post['token'], [
  1169. "order_type" => 'SPSX',
  1170. "order_code" =>$skuCode,//咨询单详情编号
  1171. "order_id" => $create,
  1172. "order_status" =>$tmp['exam_status']
  1173. ]);
  1174. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1175. if($iso==false){
  1176. unset($value['id']);
  1177. $value['creater']=$creater;
  1178. $value['createrid']=$createrid;
  1179. $value['addtime']=date("Y-m-d H:i:s");
  1180. $value['updatetime']=date("Y-m-d H:i:s");
  1181. }else{
  1182. $value['id']=$iso['id'];
  1183. $value['creater']=$creater;
  1184. $value['createrid']=$createrid;
  1185. $value['updatetime']=date("Y-m-d H:i:s");
  1186. }
  1187. $up =Db::name("good")->save($value);
  1188. if(!$up){
  1189. Db::rollback();
  1190. return error_show(1004,"提交失败");
  1191. }
  1192. }else{
  1193. Db::rollback();
  1194. return error_show(1004,"提交失败");
  1195. }
  1196. }
  1197. // if($create){
  1198. // foreach ($datas as $value){
  1199. // $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1200. // if($iso==false){
  1201. // unset($value['id']);
  1202. // $value['creater']=$creater;
  1203. // $value['createrid']=$createrid;
  1204. // $value['addtime']=date("Y-m-d H:i:s");
  1205. // $value['updatetime']=date("Y-m-d H:i:s");
  1206. // }else{
  1207. // $value['id']=$iso['id'];
  1208. // $value['creater']=$creater;
  1209. // $value['createrid']=$createrid;
  1210. // $value['updatetime']=date("Y-m-d H:i:s");
  1211. // }
  1212. // $up =Db::name("good")->save($value);
  1213. // if(!$up){
  1214. // Db::rollback();
  1215. // return error_show(1004,"提交失败");
  1216. // }
  1217. //
  1218. // //添加审核记录
  1219. // //修改状态,添加待办
  1220. // $skuCodes = array_column($data, 'skuCode', 'spuCode');
  1221. //
  1222. // ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1223. // "order_code" => $skuCodes[$value['spuCode']],//编号
  1224. // "status" => 2,//待产品审核
  1225. // "action_remark" => '',//备注
  1226. // "action_type" => "create"//新建create,编辑edit,更改状态status
  1227. // ], "SPSX", $value['status'], $value);
  1228. //
  1229. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1230. // "order_type" => 'SPSX',
  1231. // "order_code" => $skuCodes[$value['spuCode']],//咨询单详情编号
  1232. // "order_id" => isset($value['id']) ? $value['id'] : 0,
  1233. // "order_status" => 2,//待产品审核
  1234. // ]);
  1235. // }
  1236. // Db::commit();
  1237. // return app_show(0,"提交成功");
  1238. // }else{
  1239. // Db::rollback();
  1240. // return error_show(1004,"提交失败");
  1241. // }
  1242. Db::commit();
  1243. return app_show(0,"提交成功");
  1244. }catch (\Exception $e){
  1245. Db::rollback();
  1246. return error_show(1004,$e->getMessage()."|".$e->getLine());
  1247. }
  1248. }
  1249. //审核
  1250. public function online_exam(){
  1251. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1252. if($skuCode===""){
  1253. return error_show(1004,"参数skuCode不能为空");
  1254. }
  1255. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1256. if($platform==false){
  1257. return error_show(1004,"未找到数据");
  1258. }
  1259. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  1260. // if($exam_status===""){
  1261. // return error_show(1004,"参数exam_status不能为空");
  1262. // }
  1263. if($exam_status==3){
  1264. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  1265. if($online_time===""){
  1266. return error_show(1004,"参数online_time不能为空");
  1267. }
  1268. $platform['online_time']=$online_time;
  1269. }
  1270. if($exam_status==6){
  1271. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  1272. if($good_code===""){
  1273. return error_show(1004,"参数plat_code不能为空");
  1274. }
  1275. $is_exit = Db::name("good_platform")->where(["plat_code"=>$good_code,"is_del"=>0])->find();
  1276. if(($is_exit!=false && $is_exit['id'] !=$platform['id'])|| $is_exit==false){
  1277. $platform['plat_code']=$good_code;
  1278. }else{
  1279. return error_show(1004,"平台订单号 {$good_code} 已存在");
  1280. }
  1281. }
  1282. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  1283. $bifore=$platform['exam_status'];
  1284. $platform['exam_status']=$exam_status;
  1285. $platform['updatetime']=date("Y-m-d H:i:s");
  1286. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1287. if($token==''){
  1288. return error_show(105,"参数token不能为空");
  1289. }
  1290. $user =GetUserInfo($token);
  1291. if(empty($user)||$user['code']!=0){
  1292. return error_show(1002,"用户数据不存在");
  1293. }
  1294. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1295. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1296. Db::startTrans();
  1297. try {
  1298. $up = Db::name("good_platform")->save($platform);
  1299. if($up){
  1300. $data=[
  1301. "code"=>$platform['skuCode'],
  1302. "exam_status"=>$exam_status,
  1303. "type"=>2,
  1304. "exam_id"=>$createrid,
  1305. "exam_name"=>$creater,
  1306. "exam_remark"=>$exam_remark,
  1307. "addtime"=>date("Y-m-d H:i:s")
  1308. ];
  1309. $inr=Db::name("good_exam")->insert($data);
  1310. if($inr){
  1311. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1312. "order_code" => $skuCode,//编号
  1313. "status" => $bifore,
  1314. "action_remark" => '',//备注
  1315. "action_type" => "status"//新建create,编辑edit,更改状态status
  1316. ], "SPSX", $exam_status, $platform);
  1317. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1318. "order_type" => 'SPSX',
  1319. "order_code" => $skuCode,//咨询单详情编号
  1320. "order_id" => $platform['id'],
  1321. "order_status" => $exam_status,
  1322. ]);
  1323. Db::commit();
  1324. return app_show(0,"审核成功");
  1325. }else{
  1326. Db::rollback();
  1327. return error_show(1004,"审核失败");
  1328. }
  1329. }else{
  1330. Db::rollback();
  1331. return error_show(1004,"审核失败");
  1332. }
  1333. }catch (\Exception $e){
  1334. Db::rollback();
  1335. return error_show(1004,$e->getMessage());
  1336. }
  1337. }
  1338. //财务定价
  1339. public function editladder(){
  1340. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1341. if($skuCode===""){
  1342. return error_show(1004,"参数skuCode不能为空");
  1343. }
  1344. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1345. if($platform==false){
  1346. return error_show(1004,"未找到数据");
  1347. }
  1348. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1349. if($good_ladder==""){
  1350. return error_show(1004,"参数good_ladder不能为空");
  1351. }
  1352. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1353. if($proof_type===""){
  1354. return error_show(1004,"参数proof_type不能为空");
  1355. }
  1356. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1357. if($proof_url===""){
  1358. return error_show(1004,"参数proof_url不能为空");
  1359. }
  1360. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1361. if($token==''){
  1362. return error_show(105,"参数token不能为空");
  1363. }
  1364. $user =GetUserInfo($token);
  1365. if(empty($user)||$user['code']!=0){
  1366. return error_show(1002,"用户数据不存在");
  1367. }
  1368. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1369. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1370. $bifore=$platform['exam_status'];
  1371. $platform['exam_status']=4;
  1372. $platform['updatetime']=date("Y-m-d H:i:s");
  1373. Db::startTrans();
  1374. try {
  1375. foreach ($good_ladder as $value){
  1376. $lemp=[];
  1377. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1378. $lemp['skuCode']=$skuCode;
  1379. $lemp['min_num'] = $value['min_num'];
  1380. $lemp['max_num'] = 0;
  1381. $lemp['sale_price'] = $value['sale_price'];
  1382. $lemp['market_price'] = $value['market_price'];
  1383. $lemp['market_platform'] = $value['market_platform'];
  1384. $lemp['cost_fee'] = $value['cost_fee'];
  1385. $lemp['status'] = $value['status'];
  1386. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1387. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1388. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1389. $count = Db::name("good_ladder")->save($lemp);
  1390. if($count==false){
  1391. Db::rollback();
  1392. return app_show(1004,"商品起订价修改失败");
  1393. }
  1394. }
  1395. $up = Db::name("good_platform")->save($platform);
  1396. if($up){
  1397. ActionLog::logAdd($this->post['token'], [
  1398. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1399. "status" =>$bifore,//这里的status是之前的值
  1400. "action_remark" => '',//备注
  1401. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1402. ], "SPSX", $platform['exam_status'],$platform);
  1403. ProcessOrder::AddProcess($this->post['token'], [
  1404. "order_type" => 'SPSX',
  1405. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1406. "order_id" => $platform['id'],
  1407. "order_status" => $platform['exam_status']
  1408. ]);
  1409. $proof=[
  1410. 'spuCode'=>$platform['spuCode'],
  1411. 'proof_type'=>$proof_type,
  1412. 'proof_url'=>$proof_url,
  1413. 'is_del'=>0,
  1414. "creater"=>$creater,
  1415. "createrid"=>$createrid,
  1416. "addtime"=>date("Y-m-d H:i:s"),
  1417. "updatetime"=>date("Y-m-d H:i:s")
  1418. ];
  1419. $inproof = Db::name("good_proof")->insert($proof);
  1420. if($inproof==false){
  1421. Db::rollback();
  1422. return app_show(1004,"商品凭证新建失败");
  1423. }
  1424. $data=[
  1425. "code"=>$platform['skuCode'],
  1426. "type"=>2,
  1427. "exam_status"=>4,
  1428. "exam_id"=>$createrid,
  1429. "exam_name"=>$creater,
  1430. "exam_remark"=>'',
  1431. "addtime"=>date("Y-m-d H:i:s")
  1432. ];
  1433. $inr=Db::name("good_exam")->insert($data);
  1434. if($inr){
  1435. Db::commit();
  1436. return app_show(0,"审核成功");
  1437. }else{
  1438. Db::rollback();
  1439. return error_show(1004,"审核失败");
  1440. }
  1441. }else{
  1442. Db::rollback();
  1443. return error_show(1004,"审核失败");
  1444. }
  1445. }catch (\Exception $e){
  1446. Db::rollback();
  1447. return error_show(1004,$e->getMessage());
  1448. }
  1449. }
  1450. public function prooflist(){
  1451. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1452. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1453. $where =[["is_del","=",0]];
  1454. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1455. if($spuCode!==""){
  1456. $where[]=["spuCode","like","%$spuCode%"];
  1457. }
  1458. $count = Db::name("good_proof")->where($where)->count();
  1459. $total = ceil($count / $size);
  1460. $page = $page >= $total ? $total : $page;
  1461. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1462. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1463. }
  1464. /**
  1465. *
  1466. */
  1467. public function againOnline(){
  1468. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1469. if($skuCode===""){
  1470. return error_show(1004,"参数skuCode不能为空");
  1471. }
  1472. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1473. if($platform==false){
  1474. return error_show(1004,"未找到数据");
  1475. }
  1476. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1477. return error_show(1004,"商品状态有误");
  1478. }
  1479. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1480. $bifore=$platform['exam_status'];
  1481. $platform['exam_status'] = empty($nake)?1:2;
  1482. $platform['updatetime'] = date("Y-m-d H:i:s");
  1483. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1484. if($token==''){
  1485. return error_show(105,"参数token不能为空");
  1486. }
  1487. $user =GetUserInfo($token);
  1488. if(empty($user)||$user['code']!=0){
  1489. return error_show(1002,"用户数据不存在");
  1490. }
  1491. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1492. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1493. Db::startTrans();
  1494. try {
  1495. $save =Db::name("good_platform")->save($platform);
  1496. if($save){
  1497. ActionLog::logAdd($this->post['token'], [
  1498. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1499. "status" =>$bifore,//这里的status是之前的值
  1500. "action_remark" => '',//备注
  1501. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1502. ], "SPSX", $platform['exam_status'],$platform);
  1503. ProcessOrder::AddProcess($this->post['token'], [
  1504. "order_type" => 'SPSX',
  1505. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1506. "order_id" => $platform['id'],
  1507. "order_status" => $platform['exam_status']
  1508. ]);
  1509. $data=[
  1510. "code"=>$platform['skuCode'],
  1511. "type"=>2,
  1512. "exam_status"=>$platform['exam_status'] ,
  1513. "exam_id"=>$createrid,
  1514. "exam_name"=>$creater,
  1515. "exam_remark"=>'',
  1516. "addtime"=>date("Y-m-d H:i:s")
  1517. ];
  1518. $inr=Db::name("good_exam")->insert($data);
  1519. if($inr){
  1520. Db::commit();
  1521. return app_show(0,"审核成功");
  1522. }
  1523. }
  1524. Db::rollback();
  1525. return error_show(1004,"审核失败");
  1526. }catch (\Exception $e){
  1527. Db::rollback();
  1528. return error_show(1004,$e->getMessage());
  1529. }
  1530. }
  1531. public function copy(){
  1532. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1533. if($supcode==""){
  1534. return error_show(1004,"参数spuCode不能为空");
  1535. }
  1536. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1537. if($data==false){
  1538. return error_show(1004,"未找到商品数据");
  1539. }
  1540. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1541. if($token==''){
  1542. return error_show(105,"参数token不能为空");
  1543. }
  1544. $user =GetUserInfo($token);
  1545. if(empty($user)||$user['code']!=0){
  1546. return error_show(102,"用户数据不存在");
  1547. }
  1548. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1549. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1550. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1551. $ladd=[];
  1552. $newCode =makeNo("SKU");
  1553. if(!empty($nake)){
  1554. foreach ($nake as $value){
  1555. $tmp=[];
  1556. $tmp['spuCode']=$newCode;
  1557. $tmp['min_num']=$value['min_num'];
  1558. $tmp['nake_fee'] = $value['nake_fee'];
  1559. $tmp['cost_fee'] = $value['cost_fee'];
  1560. $tmp['delivery_fee'] = $value['delivery_fee'];
  1561. $tmp['cert_fee'] = $value['cert_fee'];
  1562. $tmp['mark_fee'] = $value['mark_fee'];
  1563. $tmp['package_fee'] = $value['package_fee'];
  1564. $tmp['other_fee'] = $value['other_fee'];
  1565. $tmp['nake_total'] =$value['nake_total'];
  1566. $tmp['creater_id']=$createrid;
  1567. $tmp['creater']=$creater;
  1568. $tmp['is_del']=$value['is_del'];
  1569. $tmp['addtime']=date("Y-m-d H:i:s");
  1570. $tmp['updatetime']=date("Y-m-d H:i:s");
  1571. $ladd[]=$tmp;
  1572. }
  1573. }
  1574. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1575. $specArr=[];
  1576. if(!empty($spec)){
  1577. foreach ($spec as $value){
  1578. $tmp=[];
  1579. $tmp['spuCode']=$newCode;
  1580. $tmp['spec_id']=$value['spec_id'];
  1581. $tmp['spec_value_id']=$value['spec_value_id'];
  1582. $tmp['is_del']=$value['is_del'];
  1583. $tmp['addtime']=date("Y-m-d H:i:s");
  1584. $tmp['updatetime']=date("Y-m-d H:i:s");
  1585. $specArr[]=$tmp;
  1586. }
  1587. }
  1588. Db::startTrans();
  1589. try {
  1590. unset($data['id']);
  1591. $data['spuCode']=$newCode;
  1592. $data['createrid']=$createrid;
  1593. $data['creater']=$creater;
  1594. $data['status']=7;
  1595. $data['addtime']=date("Y-m-d H:i:s");
  1596. $data['updatetime']=date("Y-m-d H:i:s");
  1597. $cre = Db::name("good_basic")->insert($data);
  1598. if($cre){
  1599. //修改状态,添加待办
  1600. ActionLog::logAdd($this->post['token'], [
  1601. "order_code" =>$newCode,//咨询单详情编号
  1602. "status" => 0,//这里的status是之前的值
  1603. "action_remark" => '',//备注
  1604. "action_type" => "create"//新建create,编辑edit,更改状态status
  1605. ], "SPCB", 7,$data);
  1606. ProcessOrder::AddProcess($this->post['token'], [
  1607. "order_type" => 'SPCB',
  1608. "order_code" =>$newCode,//咨询单详情编号
  1609. "order_id" => Db::name("good_basic")->getLastInsID(),
  1610. "order_status" =>7
  1611. ]);
  1612. if(!empty($ladd)){
  1613. $na = Db::name("good_nake")->insertAll($ladd);
  1614. if($na==0){
  1615. Db::rollback();
  1616. return error_show(1005,"成本数据复制失败");
  1617. }
  1618. }
  1619. if(!empty($specArr)){
  1620. $sp = Db::name("good_spec")->insertAll($specArr);
  1621. if($sp==0){
  1622. Db::rollback();
  1623. return error_show(1005,"规格数据复制失败");
  1624. }
  1625. }
  1626. Db::commit();
  1627. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1628. }else{
  1629. Db::rollback();
  1630. return error_show(1005,"数据复制失败");
  1631. }
  1632. }catch (\Exception $e){
  1633. Db::rollback();
  1634. return error_show(1004,$e->getMessage());
  1635. }
  1636. }
  1637. public function edit(){
  1638. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1639. if($supcode==""){
  1640. return error_show(1004,"参数spuCode不能为空");
  1641. }
  1642. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1643. if($data==false){
  1644. return error_show(1004,"未找到商品数据");
  1645. }
  1646. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  1647. return error_show(1004,"商品状态有误");
  1648. }
  1649. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1650. if($good_name==""){
  1651. return error_show(1004,"商品名称不能为空");
  1652. }
  1653. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1654. if($cat_id==''){
  1655. return error_show(1004,"商品分类不能为空");
  1656. }
  1657. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1658. // if($brandid==''){
  1659. // return error_show(1004,"商品品牌不能为空");
  1660. // }
  1661. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1662. if($unit==''){
  1663. return error_show(1004,"商品单位不能为空");
  1664. }
  1665. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  1666. :"";
  1667. if($good_type===''){
  1668. return error_show(1004,"参数good_type不能为空");
  1669. }
  1670. $moq=0;
  1671. $customized=0;
  1672. if($good_type==1){
  1673. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1674. if($moq===''){
  1675. return error_show(1004,"定制商品起订量不能为空");
  1676. }
  1677. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1678. if($customized===''){
  1679. return error_show(1004,"参数customized不能为空");
  1680. }
  1681. }
  1682. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1683. if($is_exclusive===''){
  1684. return error_show(1004,"参数is_exclusive不能为空");
  1685. }
  1686. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1687. // if($customized===''){
  1688. // return error_show(1004,"参数customized不能为空");
  1689. // }
  1690. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1691. if($tax===''){
  1692. return error_show(1004,"参数tax不能为空");
  1693. }
  1694. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1695. if($supplierNo==''){
  1696. return error_show(1004,"参数supplierNo不能为空");
  1697. }
  1698. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  1699. :"";
  1700. if($good_size==''){
  1701. return error_show(1004,"参数good_size不能为空");
  1702. }
  1703. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
  1704. :"";
  1705. if($company_id==''){
  1706. return error_show(1004,"参数companyNo不能为空");
  1707. }
  1708. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1709. if($is_auth===''){
  1710. return error_show(1004,"参数is_auth不能为空");
  1711. }
  1712. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1713. // if($auth_img==''){
  1714. // return error_show(1004,"商品不能为空");
  1715. // }
  1716. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1717. if($after_sales==""){
  1718. return error_show(1004,"参数after_sales不能为空");
  1719. }
  1720. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1721. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1722. if($good_remark===""){
  1723. return error_show(1004,"参数good_remark不能为空");
  1724. }
  1725. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1726. if($weight===""){
  1727. return error_show(1004,"参数weight不能为空");
  1728. }
  1729. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1730. if($packing_way===""){
  1731. return error_show(1004,"参数packing_way不能为空");
  1732. }
  1733. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1734. if($packing_size===""){
  1735. return error_show(1004,"参数packing_size不能为空");
  1736. }
  1737. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1738. if($packing_spec===""){
  1739. return error_show(1004,"参数packing_spec不能为空");
  1740. }
  1741. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1742. if($packing_weight===""){
  1743. return error_show(1004,"参数packing_weight不能为空");
  1744. }
  1745. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1746. if($packing_list===""){
  1747. return error_show(1004,"参数packing_list不能为空");
  1748. }
  1749. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1750. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1751. if($supply_area===""){
  1752. return error_show(1004,"参数supply_area不能为空");
  1753. }
  1754. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1755. if($delivery_place===""){
  1756. return error_show(1004,"参数delivery_place不能为空");
  1757. }
  1758. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  1759. if($origin_place===""){
  1760. return error_show(1004,"参数origin_place不能为空");
  1761. }
  1762. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  1763. if($delivery_day===""){
  1764. return error_show(1004,"参数delivery_day不能为空");
  1765. }
  1766. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  1767. :"0";
  1768. // if($lead_time===""){
  1769. // return error_show(1004,"参数lead_time不能为空");
  1770. // }
  1771. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  1772. // if($sample_day===""){
  1773. // return error_show(1004,"参数sample_day不能为空");
  1774. // }
  1775. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1776. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  1777. if($good_img===""){
  1778. return error_show(1004,"参数good_img不能为空");
  1779. }
  1780. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  1781. if($good_thumb_img===""){
  1782. return error_show(1004,"参数good_thumb_img不能为空");
  1783. }
  1784. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  1785. if($good_info_img===""){
  1786. return error_show(1004,"参数good_info_img不能为空");
  1787. }
  1788. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1789. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1790. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1791. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1792. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1793. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1794. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1795. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1796. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1797. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1798. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1799. if($market_price===""){
  1800. return error_show(1004,"参数market_price不能为空");
  1801. }
  1802. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  1803. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  1804. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  1805. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  1806. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  1807. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1808. // if($is_step===""){
  1809. // return error_show(1004,"参数is_step不能为空");
  1810. // }
  1811. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1812. // if($is_step==1 && $good_ladder==""){
  1813. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  1814. // }
  1815. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  1816. Db::startTrans();
  1817. try {
  1818. $temp=[
  1819. "good_name"=>$good_name,
  1820. "cat_id"=>$cat_id,
  1821. 'brand_id'=>$brandid,
  1822. "good_unit"=>$unit,
  1823. "good_type"=>$good_type,
  1824. "companyNo"=>$company_id,
  1825. "moq"=>$moq,
  1826. "is_exclusive"=>$is_exclusive,
  1827. "customized"=>$customized,
  1828. "tax"=>$tax,
  1829. "supplierNo"=>$supplierNo,
  1830. "is_auth"=>$is_auth,
  1831. "good_size"=>$good_size,
  1832. "auth_img"=>$auth_img,
  1833. "after_sales"=>$after_sales,
  1834. "craft_desc"=>$craft_desc,
  1835. "good_remark"=>$good_remark,
  1836. "weight"=>$weight,
  1837. "packing_way"=>$packing_way,
  1838. "packing_size"=>$packing_size,
  1839. "packing_spec"=>$packing_spec,
  1840. "packing_list"=>$packing_list,
  1841. "packing_weight"=>$packing_weight,
  1842. "good_bar"=>$good_bar,
  1843. "supply_area"=>$supply_area,
  1844. "delivery_place"=>$delivery_place,
  1845. "origin_place"=>$origin_place,
  1846. "delivery_day"=>$delivery_day,
  1847. "lead_time"=>$lead_time,
  1848. "sample_day"=>$sample_day,
  1849. "sample_fee"=>$sample_fee,
  1850. "good_img"=>$good_img,
  1851. "good_thumb_img"=>$good_thumb_img,
  1852. "good_info_img"=>$good_info_img,
  1853. "cert_fee"=>$cert_fee,
  1854. "packing_fee"=>$packing_fee,
  1855. "is_diff"=>$is_diff,
  1856. "config"=>$config,
  1857. "other_config"=>$other_config,
  1858. "is_stock"=>$is_stock,
  1859. "cost_fee"=>$cost_fee,
  1860. "mark_fee"=>$mark_fee,
  1861. "demo_fee"=>$demo_fee,
  1862. "open_fee"=>$open_fee,
  1863. "noble_metal"=>$noble_metal,
  1864. "noble_weight"=>$noble_weight,
  1865. "is_gold_price"=>$is_gold_price,
  1866. "market_price"=>$market_price,
  1867. "nake_price"=>$nake_price,
  1868. "cgd_gold_price"=>$cgd_gold_price,
  1869. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1870. "status"=>"0",
  1871. "updatetime"=>date("Y-m-d H:i:s")
  1872. ];
  1873. $field = array_diff_assoc($temp,$data);
  1874. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1875. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1876. $var = array_diff($temp,$data);
  1877. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  1878. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  1879. if($up){
  1880. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,$this->post['token'],$this->post);
  1881. //修改状态,添加待办
  1882. ActionLog::logAdd($this->post['token'], [
  1883. "order_code" =>$supcode,//咨询单详情编号
  1884. "status" => $data['status'],//这里的status是之前的值
  1885. "action_remark" => '',//备注
  1886. "action_type" => "create"//新建create,编辑edit,更改状态status
  1887. ], "SPCB", 0,$temp);
  1888. ProcessOrder::AddProcess($this->post['token'], [
  1889. "order_type" => 'SPCB',
  1890. "order_code" =>$supcode,//咨询单详情编号
  1891. "order_id" => $data['id'],
  1892. "order_status" =>0
  1893. ]);
  1894. if($speclist!=="" && !empty($speclist)){
  1895. foreach ($speclist as $value){
  1896. $lemp=[];
  1897. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1898. $lemp['spuCode']=$supcode;
  1899. $lemp['spec_id'] = $value['spec_id'];
  1900. $lemp['spec_value_id'] = $value['spec_value_id'];
  1901. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1902. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1903. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1904. $count = Db::name("good_spec")->save($lemp);
  1905. if($count==false){
  1906. Db::rollback();
  1907. return app_show(1004,"商品规格值修改失败");
  1908. }
  1909. }
  1910. }
  1911. if($good_ladder!=="" && !empty($good_ladder)){
  1912. $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  1913. $top_cat_id = made($cat_id);//获取所有分类
  1914. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1915. foreach ($good_ladder as $value){
  1916. $lemp=[];
  1917. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1918. $lemp['spuCode']=$supcode;
  1919. $lemp['min_num'] = $value['min_num'];
  1920. $lemp['nake_fee'] = $value['nake_fee'];
  1921. $lemp['cost_fee'] = $value['cost_fee'];
  1922. $lemp['delivery_fee'] = $value['delivery_fee'];
  1923. $lemp['cert_fee'] = $value['cert_fee'];
  1924. $lemp['mark_fee'] = $value['mark_fee'];
  1925. $lemp['package_fee'] = $value['package_fee'];
  1926. $lemp['other_fee'] = $value['other_fee'];
  1927. if ($is_gold_price == 1 && $top_cat_id == 6) {
  1928. // $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  1929. // ->order("addtime desc")->find();
  1930. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  1931. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1932. //成本总计启用实时金价时,采用供应商实时金价
  1933. $lemp['nake_total'] =$noble_weight *$cgd_gold_price+ $value['cost_fee'] * $noble_weight +
  1934. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1935. }else{
  1936. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1937. }
  1938. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : 0;
  1939. $lemp['creater'] = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1940. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1941. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1942. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1943. $count = Db::name("good_nake")->save($lemp);
  1944. if($count==false){
  1945. Db::rollback();
  1946. return app_show(1004,"商品规成本修改失败");
  1947. }
  1948. }
  1949. }
  1950. Db::commit();
  1951. return app_show(0,"更新成功");
  1952. }else{
  1953. Db::rollback();
  1954. return error_show(1005,"更新失败");
  1955. }
  1956. }catch (\Exception $e){
  1957. Db::rollback();
  1958. return error_show(1004,$e->getMessage());
  1959. }
  1960. }
  1961. public function checkPrice(){
  1962. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  1963. if($spuCode==""){
  1964. return error_show(1005,"参数spuCode不能为空");
  1965. }
  1966. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  1967. if($good==false){
  1968. return error_show(1005,"商品数据未找到");
  1969. }
  1970. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  1971. if($num==""){
  1972. return error_show(1005,"参数min_num不能为空");
  1973. }
  1974. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
  1975. ->order("min_num desc")->find();
  1976. if($nakelist==false){
  1977. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
  1978. return error_show(1010,"起订量不足{$nakelist['min_num']}");
  1979. }
  1980. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  1981. $budget = isset($catinfo['sale_rate']) ? $catinfo['sale_rate']/100:0;
  1982. $top_cat_id = made($catinfo['id']);//获取所有分类
  1983. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1984. $sale_cost_fee = 0;
  1985. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  1986. // $saleprice = $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*$good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee'];
  1987. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  1988. $saleprice = ($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee']) / (1 - $budget);
  1989. //计算工艺费
  1990. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  1991. $sale_cost_fee = (($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['other_fee'] + $nakelist['delivery_fee']) / (1 - $budget) - ($nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee'])) / $good['noble_weight'] - $good["cgd_gold_price"];
  1992. }else{
  1993. $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  1994. }
  1995. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  1996. }
  1997. //咨询成交商品池 添加上线商品
  1998. public function onlineZixunGoods()
  1999. {
  2000. $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim');
  2001. $val = Validate::rule([
  2002. 'platform|所选上线平台' => 'require|number|gt:0',
  2003. 'codes|所选上线商品编号' => 'require',
  2004. 'online_reason|上线原因' => 'require',
  2005. 'online_remark|上线备注' => 'require',
  2006. 'token' => 'require',
  2007. ]);
  2008. if (!$val->check($param)) return error_show(1004, $val->getError());
  2009. $good_zixun_list = Db::name("good_zixun")
  2010. ->where(["is_del" => 0])
  2011. ->whereIn('spuCode', $param['codes'])
  2012. ->column('*', 'spuCode');
  2013. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2014. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  2015. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2016. $isonline = Db::name("good_platform")
  2017. ->alias('gp')
  2018. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2019. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2020. ->whereIn('gp.spuCode', $param['codes'])
  2021. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2022. ->select()
  2023. ->toArray();
  2024. if (!empty($isonline)) {
  2025. foreach ($isonline as &$v) {
  2026. $spec = Db::name("good_spec")
  2027. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2028. ->select()
  2029. ->toArray();
  2030. $speclist = [];
  2031. if (!empty($spec)) {
  2032. foreach ($spec as $val) {
  2033. $temp = [];
  2034. $temp['id'] = $val['id'];
  2035. $temp['spuCode'] = $val['spuCode'];
  2036. $temp['spec_id'] = $val['spec_id'];
  2037. $temp['spec_value_id'] = $val['spec_value_id'];
  2038. $temp['is_del'] = $val['is_del'];
  2039. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2040. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2041. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2042. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2043. $speclist[] = $temp;
  2044. }
  2045. }
  2046. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2047. }
  2048. return app_show(1009, "存在已上线产品", $isonline);
  2049. }
  2050. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2051. $user = GetUserInfo($param['token']);
  2052. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2053. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2054. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2055. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2056. $i = 0;
  2057. $all_nakes = Db::name("good_nake")
  2058. ->where(["is_del" => 0])->fetchSql()
  2059. ->whereIn('spuCode', $param['codes'])
  2060. ->group('spuCode')
  2061. ->column('count(`id`) total', 'spuCode');
  2062. $all_good = Db::name('good')
  2063. ->where('is_del', 0)
  2064. ->whereIn('spuCode', $param['codes'])
  2065. ->column('id', 'spuCode');
  2066. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2067. $all_good_basic = Db::name('good_basic')
  2068. ->where('is_del', 0)
  2069. ->whereIn('spuCode', $param['codes'])
  2070. ->column('id', 'spuCode');
  2071. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2072. foreach ($param['codes'] as $value) {
  2073. //改变编码规则,将原来的skuCode后两位换成序列号
  2074. //str_pad字符串填充
  2075. $skuCode = makeNo("SN");
  2076. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2077. $data[] = [
  2078. "spuCode" => $value,
  2079. "skuCode" => $skuCode,
  2080. "platform_code" => $param['platform'],
  2081. "online_reason" => $param['online_reason'],
  2082. "online_remark" => $param['online_remark'],
  2083. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2084. "is_online" => 0,
  2085. "status" => 0,
  2086. "is_del" => 0,
  2087. "creater" => $creater,
  2088. "createrid" => $createrid,
  2089. "addtime" => date("Y-m-d H:i:s"),
  2090. "updatetime" => date("Y-m-d H:i:s")
  2091. ];
  2092. //good表
  2093. if (!isset($all_good[$value])) {
  2094. $good_insert_data[] = [
  2095. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2096. 'good_code' => $good_zixun_list[$value]['good_code'],
  2097. 'good_name' => $good_zixun_list[$value]['good_name'],
  2098. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2099. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2100. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2101. 'good_type' => $good_zixun_list[$value]['good_type'],
  2102. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2103. 'moq' => $good_zixun_list[$value]['moq'],
  2104. 'customized' => $good_zixun_list[$value]['customized'],
  2105. 'tax' => $good_zixun_list[$value]['tax'],
  2106. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2107. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2108. 'is_stock' => '',
  2109. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2110. 'after_sales' => '',
  2111. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2112. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2113. 'good_size' => '',
  2114. 'weight' => $good_zixun_list[$value]['weight'],
  2115. 'packing_way' => '',
  2116. 'packing_size' => '',
  2117. 'packing_spec' => '',
  2118. 'packing_list' => '',
  2119. 'packing_weight' => '',
  2120. 'good_bar' => '',
  2121. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2122. 'delivery_place' => '',
  2123. 'origin_place' => '',
  2124. 'delivery_day' => 0,
  2125. 'lead_time' => '',
  2126. 'sample_day' => '',
  2127. 'sample_fee' => '',
  2128. 'good_img' => $good_zixun_list[$value]['good_img'],
  2129. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2130. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  2131. 'cert_fee' => '',
  2132. 'packing_fee' => '',
  2133. 'cost_fee' => '',
  2134. 'mark_fee' => '',
  2135. 'demo_fee' => '',
  2136. 'open_fee' => '',
  2137. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2138. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2139. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2140. 'cgd_gold_price' => '',
  2141. 'market_price' => '',
  2142. 'nake_price' => '',
  2143. 'is_step' => '',
  2144. 'is_online' => '',
  2145. 'status' => 1,//待完善成本
  2146. 'createrid' => $createrid,
  2147. 'creater' => $creater,
  2148. 'is_del' => 0,
  2149. 'field_change' => '',
  2150. 'addtime' => date('Y-m-d H:i:s'),
  2151. 'updatetime' => date('Y-m-d H:i:s'),
  2152. 'is_exclusive' => '',
  2153. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2154. 'config' => $good_zixun_list[$value]['config'],
  2155. 'other_config' => $good_zixun_list[$value]['other_config'],
  2156. ];
  2157. }
  2158. //good_basic表
  2159. if (!isset($all_good_basic[$value])) {
  2160. $good_basic_insert_data[] = [
  2161. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2162. 'good_code' => $good_zixun_list[$value]['good_code'],
  2163. 'good_name' => $good_zixun_list[$value]['good_name'],
  2164. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2165. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2166. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2167. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2168. 'good_type' => $good_zixun_list[$value]['good_type'],
  2169. 'moq' => $good_zixun_list[$value]['moq'],
  2170. 'customized' => $good_zixun_list[$value]['customized'],
  2171. 'tax' => $good_zixun_list[$value]['tax'],
  2172. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2173. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2174. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2175. 'after_sales' => '',
  2176. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2177. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2178. 'weight' => $good_zixun_list[$value]['weight'],
  2179. 'packing_way' => '',
  2180. 'packing_size' => '',
  2181. 'packing_spec' => '',
  2182. 'packing_list' => '',
  2183. 'packing_weight' => '',
  2184. 'good_bar' => '',
  2185. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2186. 'delivery_place' => '',
  2187. 'origin_place' => '',
  2188. 'delivery_day' => '',
  2189. 'lead_time' => '',
  2190. 'sample_day' => '',
  2191. 'sample_fee' => '',
  2192. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2193. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2194. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2195. 'cert_fee' => '',
  2196. 'packing_fee' => '',
  2197. 'cost_fee' => '',
  2198. 'mark_fee' => '',
  2199. 'demo_fee' => '',
  2200. 'open_fee' => '',
  2201. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2202. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2203. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2204. 'cgd_gold_price' => '',
  2205. 'market_price' => '',
  2206. 'nake_price' => '',
  2207. 'is_step' => '',
  2208. 'is_online' => '',
  2209. 'status' => 8,//咨询商品待编辑
  2210. 'createrid' => $createrid,
  2211. 'creater' => $creater,
  2212. 'field_change' => '',
  2213. 'is_del' => 0,
  2214. 'addtime' => date('Y-m-d H:i:s'),
  2215. 'updatetime' => date('Y-m-d H:i:s'),
  2216. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2217. 'config' => $good_zixun_list[$value]['config'],
  2218. 'other_config' => $good_zixun_list[$value]['other_config'],
  2219. ];
  2220. }
  2221. //good_spec
  2222. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2223. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2224. foreach ($spec_list as $spec) {
  2225. $temp = Db::name('good_spec')
  2226. ->field('id')
  2227. ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2228. ->find();
  2229. if (!empty($temp)) {
  2230. $good_spec_insert_data[] = [
  2231. 'spuCode' => $value,
  2232. 'spec_id' => $spec['specid'],
  2233. 'spec_value_id' => $spec['spec_value_id'],
  2234. 'is_del' => 0,
  2235. 'addtime' => date('Y-m-d H:i:s'),
  2236. 'updatetime' => date('Y-m-d H:i:s'),
  2237. ];
  2238. }
  2239. }
  2240. }
  2241. $i++;
  2242. }
  2243. if (!empty($isonline)) {
  2244. return app_show(1009, "存在已上线产品", $isonline);
  2245. }
  2246. Db::startTrans();
  2247. try {
  2248. $create = Db::name("good_platform")->insertAll($data);
  2249. Db::name("good_zixun")
  2250. ->where(["is_del" => 0, 'status' => 1])
  2251. ->whereIn('spuCode', $param['codes'])
  2252. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2253. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2254. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2255. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2256. if ($create) {
  2257. foreach ($good_basic_insert_data as $value) {
  2258. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2259. "order_code" =>$value['spuCode'],//
  2260. "status" => 8,//待产品审核
  2261. "action_remark" => '',//备注
  2262. "action_type" => "create"//新建create,编辑edit,更改状态status
  2263. ], "SPCB", $value['status'], $value);
  2264. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2265. "order_type" => 'SPCB',
  2266. "order_code" =>$value['spuCode'],//
  2267. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2268. "order_status" => 8,//待产品审核
  2269. ]);
  2270. }
  2271. foreach ($data as $value) {
  2272. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2273. "order_code" =>$value['skuCode'],//
  2274. "status" => 0,//待产品审核
  2275. "action_remark" => '',//备注
  2276. "action_type" => "create"//新建create,编辑edit,更改状态status
  2277. ], "SPSX", $value['exam_status'], $value);
  2278. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2279. "order_type" => 'SPSX',
  2280. "order_code" =>$value['skuCode'],//
  2281. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2282. "order_status" =>$value['exam_status'],//待产品审核
  2283. ]);
  2284. }
  2285. Db::commit();
  2286. return app_show(0, "提交成功");
  2287. } else {
  2288. Db::rollback();
  2289. return error_show(1004, "提交失败");
  2290. }
  2291. } catch (Exception $exception) {
  2292. Db::rollback();
  2293. return error_show(1005, $exception->getMessage());
  2294. }
  2295. }
  2296. }