Goodup.php 125 KB

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