Goodup.php 122 KB

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