Goodup.php 123 KB

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