Goodup.php 126 KB

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