Consult.php 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','=',$infoNo];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  59. ->count();
  60. $total = ceil($count / $size);
  61. $page = $page >= $total ? $total : $page;
  62. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  63. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  64. $data=[];
  65. foreach ($list as $value){
  66. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  67. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  68. true):[];
  69. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  70. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  71. $value['khname']="";
  72. if($value['khNo']!==""){
  73. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  74. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  75. }
  76. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  77. $data[]=$value;
  78. }
  79. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  80. }
  81. public function info(){
  82. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  83. if($id==""){
  84. return error_show(1002,"咨询单编号不能为空");
  85. }
  86. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  87. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  88. $fo['can']=$in;
  89. if(empty($fo)){
  90. return error_show(1002,"未找到咨询单编号");
  91. }else{
  92. return app_show(0,"获取成功",$fo);
  93. }
  94. }
  95. public function del(){
  96. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  97. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  98. if($de==false){
  99. return error_show(1002,'咨询单信息未找到');
  100. }
  101. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  102. if($dell){
  103. return error_show(0,"删除成功");
  104. }else
  105. return error_show(1002,"删除失败");
  106. }
  107. public function create(){
  108. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  109. if($is_project===""){
  110. return error_show(1002,"参数is_project不能为空");
  111. }
  112. if($is_project==1){
  113. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  114. if($projectNo===""){
  115. return error_show(1002,"参数projectNo不能为空");
  116. }
  117. }
  118. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  119. if($khNo===""){
  120. return error_show(1002,"参数khNo不能为空");
  121. }
  122. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  123. if($companyNo===""){
  124. return error_show(1002,"参数companyNo不能为空");
  125. }
  126. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  127. if($endtime===""){
  128. return error_show(1002,"参数endtime不能为空");
  129. }
  130. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  131. "";
  132. if($platform_code===""){
  133. return error_show(1002,"参数platform_code不能为空");
  134. }
  135. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  136. if($ladder==""){
  137. return error_show(1005,"参数ladder不能为空");
  138. }
  139. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  140. if($token==''){
  141. return error_show(105,"参数token不能为空");
  142. }
  143. $user =GetUserInfo($token);
  144. if(empty($user)||$user['code']!=0){
  145. return error_show(102,"用户数据不存在");
  146. }
  147. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  148. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  149. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  150. $zxNo=makeNo("ZX");
  151. Db::startTrans();
  152. try{
  153. $data=[
  154. "zxNo"=>$zxNo,
  155. "createrid"=>$createrid,
  156. "creater"=>$creater,
  157. "is_project"=>$is_project,
  158. "projectNo"=>isset($projectNo) ? $projectNo:"",
  159. "khNo"=>$khNo,
  160. "companyNo"=>$companyNo,
  161. "endtime"=>$endtime,
  162. "salesman"=>$creater,
  163. "platform_code"=>$platform_code,
  164. "saleid"=>$createrid,
  165. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  166. "status"=>0,
  167. "is_del"=>0,
  168. "addtime"=>date("Y-m-d H:i:s"),
  169. "updatetime"=>date("Y-m-d H:i:s"),
  170. ];
  171. $zx = Db::name("consult_order")->insert($data);
  172. if($zx){
  173. foreach ($ladder as $value){
  174. $infoNo=makeNo("IF");
  175. $specinfo=[];
  176. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  177. foreach ($value["specinfo"] as $v){
  178. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  179. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  180. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  181. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  182. $specinfo[]=$v;
  183. }
  184. }
  185. $info=[
  186. "infoNo"=>$infoNo,
  187. "zxNo"=>$zxNo,
  188. "spuCode"=>"",
  189. "good_name"=>$value['good_name'],
  190. "good_img"=>$value['good_img'],
  191. "cat_id"=>$value['cat_id'],
  192. "unit"=>$value['unit'],
  193. "brand_id"=>$value['brand_id'],
  194. "arrival_time"=>$value['arrival_time'],
  195. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  196. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  197. "is_addrs"=>$value['is_addrs'],
  198. "is_custom"=>$value['is_custom'],
  199. "metal_id"=>$value['metal_id'],
  200. "config"=>isset($value['config'])?$value['config']:"",
  201. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  202. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  203. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  204. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  205. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  206. "budget_price"=>$value['budget_price'],
  207. "num"=>$value['num'],
  208. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  209. "use_desc"=>$value['use_desc'],
  210. "remark"=>$value['remark'],
  211. "status"=>1,
  212. "is_del"=>0,
  213. "addtime"=>date("Y-m-d H:i:s"),
  214. "updatetime"=>date("Y-m-d H:i:s"),
  215. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  216. ];
  217. $up = Db::name("consult_info")->insert($info);
  218. if(!$up){
  219. Db::rollback();
  220. return error_show(1004,'添加失败');
  221. }else{
  222. //修改状态,添加待办
  223. ActionLog::logAdd($this->post['token'], [
  224. "order_code" => $infoNo,//咨询单详情编号
  225. "status" => 1,//这里的status是之前的值
  226. "action_remark" => '',//备注
  227. "action_type" => "create"//新建create,编辑edit,更改状态status
  228. ], "ZXD", 1, $info);
  229. ProcessOrder::AddProcess($this->post['token'], [
  230. "order_type" => 'ZXD',
  231. "order_code" => $infoNo,//咨询单详情编号
  232. "order_id" => 0,
  233. "order_status" => 1
  234. ]);
  235. }
  236. }
  237. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  238. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  239. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  240. ProcessOrder::AddProcess($this->post['token'],$process);
  241. Db::commit();
  242. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  243. }else{
  244. Db::rollback();
  245. return error_show(1004,"新建失败");
  246. }
  247. }catch (\Exception $e){
  248. Db::rollback();
  249. return error_show(1003,$e->getMessage());
  250. }
  251. }
  252. public function zxinfo(){
  253. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  254. if($infoNo==""){
  255. return error_show(1004,"参数infoNo不能为空");
  256. }
  257. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  258. if($zxinfo==false){
  259. return error_show(1004,"未找到信息数据");
  260. }
  261. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  262. if($zxorder==false){
  263. return error_show(1004,"未找到咨询信息数据");
  264. }
  265. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  266. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  267. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  268. $zxinfo['khname']="";
  269. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  270. $zxinfo['khNo']="";
  271. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  272. $zxinfo['brand']="";
  273. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  274. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  275. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  276. $zxinfo['company']="";
  277. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  278. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  279. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  280. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  281. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  282. $zxinfo['project_name']="";
  283. $zxinfo['budget_total']="";
  284. $zxinfo['departinfo']=[];
  285. $zxinfo['unit_name']="";
  286. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  287. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  288. if($zxorder['khNo']!==""){
  289. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  290. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  291. $zxinfo['khNo']= $zxorder['khNo'];
  292. }
  293. if($zxinfo['unit']!==""){
  294. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  295. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  296. }
  297. if($zxinfo['brand_id']!==""){
  298. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  299. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  300. }
  301. if($zxorder['companyNo']!==""){
  302. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  303. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  304. }
  305. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  306. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  307. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  308. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  309. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  310. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  311. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  312. }
  313. if($zxorder['depart']>0){
  314. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  315. }
  316. if($zxorder['platform_code']>0){
  317. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  318. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  319. }
  320. return app_show(0,"获取成功",$zxinfo);
  321. }
  322. public function zxedit(){
  323. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  324. if($infoNo==""){
  325. return error_show(1004,"参数infoNo不能为空");
  326. }
  327. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  328. if($zxinfo==false){
  329. return error_show(1004,"未找到信息数据");
  330. }
  331. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  332. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  333. if($good_name==""){
  334. return error_show(1003,"参数good_name不能为空");
  335. }
  336. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  337. if($good_img==""){
  338. return error_show(1003,"参数good_img不能为空");
  339. }
  340. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  341. if($cat_id==""){
  342. return error_show(1003,"参数cat_id不能为空");
  343. }
  344. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  345. if($unit==""){
  346. return error_show(1003,"参数unit不能为空");
  347. }
  348. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  349. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  350. if($arrival_time==""){
  351. return error_show(1003,"参数arrival_time不能为空");
  352. }
  353. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  354. if($specin==""){
  355. return error_show(1003,"参数specinfo不能为空");
  356. }
  357. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  358. // if($cost_desc==""){
  359. // return error_show(1003,"参数cost_desc不能为空");
  360. // }
  361. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  362. if($is_addrs===""){
  363. return error_show(1003,"参数is_addrs不能为空");
  364. }
  365. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  366. if($is_custom===""){
  367. return error_show(1003,"参数is_custom不能为空");
  368. }
  369. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  370. if($metal_id===""){
  371. return error_show(1003,"参数metal_id不能为空");
  372. }
  373. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  374. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  375. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  376. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  377. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  378. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  379. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  380. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  381. if($num===""){
  382. return error_show(1003,"参数num不能为空");
  383. }
  384. if($budget_price===""){
  385. return error_show(1003,"参数budget_price不能为空");
  386. }
  387. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  388. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  389. if($use_desc==""){
  390. return error_show(1003,"参数use_desc不能为空");
  391. }
  392. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  393. if($remark==""){
  394. return error_show(1003,"参数remark不能为空");
  395. }
  396. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  397. if($endtime==""){
  398. return error_show(1003,"参数endtime不能为空");
  399. }
  400. if($metal_id!=0){
  401. if($config==""){
  402. return error_show(1003,"参数config不能为空");
  403. }
  404. if($other_config==""){
  405. return error_show(1003,"参数other_config不能为空");
  406. }
  407. if($specs_weight===""){
  408. return error_show(1003,"参数specs_weight不能为空");
  409. }
  410. if($gold_price===""){
  411. return error_show(1003,"参数gold_price不能为空");
  412. }
  413. }
  414. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  415. if($token==''){
  416. return error_show(102,"参数token不能为空");
  417. }
  418. $user =GetUserInfo($token);
  419. if(empty($user)||$user['code']!=0){
  420. return error_show(105,"用户数据不存在");
  421. }
  422. $specinfo=[];
  423. foreach ($specin as $v){
  424. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  425. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  426. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  427. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  428. $specinfo[]=$v;
  429. }
  430. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  431. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  432. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  433. Db::startTrans();
  434. try{
  435. $innew =makeNo("IF");
  436. $info=[
  437. "infoNo"=>$innew,
  438. "zxNo"=>$zxinfo['zxNo'],
  439. "spuCode"=>"",
  440. "good_name"=>$good_name,
  441. "good_img"=>$good_img,
  442. "cat_id"=>$cat_id,
  443. "unit"=>$unit,
  444. "brand_id"=>$brand_id,
  445. "arrival_time"=>$arrival_time,
  446. "specinfo"=>json_encode($specinfo),
  447. // "color"=>$color,
  448. // "material"=>$material,
  449. "cost_desc"=>$cost_desc,
  450. "is_addrs"=>$is_addrs,
  451. "is_custom"=>$is_custom,
  452. "metal_id"=>$metal_id,
  453. "config"=>$config,
  454. "other_config"=>$other_config,
  455. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  456. "gold_price"=>$gold_price===""? 0 : $gold_price,
  457. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  458. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  459. "budget_price"=>$budget_price,
  460. "num"=>$num,
  461. "pgNo"=>$pgNo,
  462. "use_desc"=>$use_desc,
  463. "remark"=>$remark,
  464. "status"=>1,
  465. "is_del"=>0,
  466. "addtime"=>date("Y-m-d H:i:s"),
  467. "updatetime"=>date("Y-m-d H:i:s"),
  468. 'bargain_status'=>1,
  469. 'enclosure_file'=>$enclosure_file
  470. ];
  471. $up = Db::name("consult_info")->insert($info);
  472. if($up){
  473. //修改状态,添加待办
  474. ActionLog::logAdd($this->post['token'], [
  475. "order_code" => $innew,//咨询单详情编号
  476. "status" => 1,//这里的status是之前的值
  477. "action_remark" => '',//备注
  478. "action_type" => "create"//新建create,编辑edit,更改状态status
  479. ], "ZXD", 1, $info);
  480. ProcessOrder::AddProcess($this->post['token'], [
  481. "order_type" => 'ZXD',
  482. "order_code" => $innew,//咨询单详情编号
  483. "order_id" => 0,
  484. "order_status" => 1
  485. ]);
  486. if (!empty($bidlist)){
  487. foreach ($bidlist as $value){
  488. unset($value['id']);
  489. $value['infoNo']=$innew;
  490. $value['bidNo']=makeNo("BD");
  491. $value['spuCode']=makeNo("SKU");
  492. $value['status'] =0;
  493. $value['updatetime'] =date("Y-m-d H:i:s");
  494. $in = Db::name("consult_bids")->insert($value);
  495. if($in==false){
  496. Db::rollback();
  497. return error_show(1004,"反馈商品新建失败");
  498. }
  499. }
  500. }
  501. $zxinfo["bargain_status"] =1;
  502. $zxinfo["bargain_code"] =$innew;
  503. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  504. $bar=Db::name("consult_info")->save($zxinfo);
  505. if($bar==false){
  506. Db::rollback();
  507. return error_show(1004,"反馈商品更新失败");
  508. }else{
  509. //修改状态,添加待办
  510. ActionLog::logAdd($this->post['token'], [
  511. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  512. "status" => $zxinfo['status'],//这里的status是之前的值
  513. "action_remark" => '',//备注
  514. "action_type" => "edit"//新建create,编辑edit,更改状态status
  515. ], "ZXD", $zxinfo['status'], $zxinfo);
  516. // 并没有修改状态
  517. // ProcessOrder::AddProcess($this->post['token'], [
  518. // "order_type" => 'ZXD',
  519. // "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  520. // "order_id" => $zxinfo['id'],
  521. // "order_status" => $zxinfo['status']
  522. // ]);
  523. }
  524. //更新consule_order记录
  525. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  526. Db::commit();
  527. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  528. }
  529. }catch (\Exception $e){
  530. Db::rollback();
  531. return error_show(1004,$e->getMessage());
  532. }
  533. }
  534. //** 发布竞标任务 */
  535. public function bargain(){
  536. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  537. if($infoNo==""){
  538. return error_show(1004,"参数infoNo不能为空");
  539. }
  540. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  541. if($zxinfo==false){
  542. return error_show(1004,"未找到信息数据");
  543. }
  544. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  545. if($status===""){
  546. return error_show(1004,"参数status不能为空");
  547. }
  548. if($status==1&&$zxinfo['status']>1){
  549. $zxinfo['bargain_num']=+1;
  550. }
  551. $old_zxinfo_status = $zxinfo['status'];
  552. $zxinfo['status']=$status;
  553. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  554. $up = Db::name("consult_info")->save($zxinfo);
  555. if($up){
  556. //修改状态,添加待办
  557. ActionLog::logAdd($this->post['token'], [
  558. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  559. "status" => $old_zxinfo_status,//这里的status是之前的值
  560. "action_remark" => '',//备注
  561. "action_type" => "status"//新建create,编辑edit,更改状态status
  562. ], "ZXD", $zxinfo['status'], $zxinfo);
  563. ProcessOrder::AddProcess($this->post['token'], [
  564. "order_type" => 'ZXD',
  565. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  566. "order_id" => $zxinfo['id'],
  567. "order_status" => $zxinfo['status']
  568. ]);
  569. return app_show(0,"状态更新成功");
  570. }else{
  571. return error_show(1003,"状态更新失败");
  572. }
  573. }
  574. public function feadback(){
  575. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  576. if($infoNo==""){
  577. return error_show(1002,"参数infoNo不能为空");
  578. }
  579. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  580. if($zxinfo==false){
  581. return error_show(1003,"未找到信息数据");
  582. }
  583. if($zxinfo['status']!=1){
  584. return error_show(1004,"任务未进行");
  585. }
  586. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  587. if($zx==false){
  588. return error_show(1003,"未找咨询信息数据");
  589. }
  590. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  591. if($pname==""){
  592. return error_show(1002,"参数pname不能为空");
  593. }
  594. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  595. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  596. if($cat_id==""){
  597. return error_show(1002,"参数cat_id不能为空");
  598. }
  599. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  600. if($specin==""){
  601. return error_show(1003,"参数specinfo不能为空");
  602. }
  603. $specinfo=[];
  604. foreach ($specin as $v){
  605. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  606. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  607. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  608. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  609. $specinfo[]=$v;
  610. }
  611. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  612. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  613. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  614. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  615. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  616. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  617. :"";
  618. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  619. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  620. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  621. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  622. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  623. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  624. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  625. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  626. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  627. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  628. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  629. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  630. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  631. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  632. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  633. ($this->post['pakge_fee']):"";
  634. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  635. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  636. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  637. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  638. if($nake_fee==="" ){
  639. return error_show(1004,"参数nake_fee不能为空");
  640. }
  641. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  642. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  643. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  644. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  645. if($token==''){
  646. return error_show(1002,"参数token不能为空");
  647. }
  648. $user =GetUserInfo($token);
  649. if(empty($user)||$user['code']!=0){
  650. return error_show(1005,"用户数据不存在");
  651. }
  652. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  653. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  654. $bidNo=makeNo("BD");
  655. $spucode=makeNo("SKU");
  656. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  657. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  658. //部分参数的大小校验
  659. $vali = Validate::rule([
  660. 'expire_day|有效时长'=>'require|elt:214748364',
  661. 'delivery_day|物流时长'=>'require|elt:214748364',
  662. 'work_day|生产工期'=>'require|elt:214748364',
  663. 'weight|总重量'=>'require|max:10',
  664. ]);
  665. $temp = [
  666. 'expire_day'=>$expire_day,
  667. 'delivery_day'=>$delivery_day,
  668. 'work_day'=>$work_day,
  669. 'weight'=>$weight,
  670. ];
  671. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  672. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  673. $cat_top_list = made($cat_id);
  674. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  675. if ($is_gold_price == 1 && $cat_top_id == 6) {
  676. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  677. ->find();
  678. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  679. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  680. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  681. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  682. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  683. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  684. $saleprice = $total_fee/ (1 - $budget);
  685. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  686. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  687. }else{
  688. if($nake_fee){
  689. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight +
  690. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  691. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  692. }else{
  693. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee) /
  694. (1 - $budget);
  695. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee;
  696. }
  697. }
  698. $data=[
  699. "bidNo"=>$bidNo,
  700. "infoNo"=>$infoNo,
  701. "zxNo"=>$zxinfo['zxNo'],
  702. "spuCode"=>$spucode,
  703. "good_name"=>$pname,
  704. "brand_id"=>$brandid,
  705. "cat_id"=>$cat_id,
  706. "specinfo"=>json_encode($specinfo),
  707. "unit_id"=>$unit_id,
  708. "cost_desc"=>$cost_desc,
  709. "work_day"=>$work_day,
  710. "delivery_day"=>$delivery_day,
  711. "good_img"=>$good_img,
  712. "expire_day"=>$expire_day,
  713. "origin_place"=>$origin_place,
  714. "supplierNo"=>$supplierNo,
  715. "pay_way"=>$pay_way,
  716. "tax"=>$tax,
  717. "send_way"=>$send_way,
  718. "metal_id"=>$metal_id,
  719. "is_gold_price"=>$is_gold_price,
  720. "config"=>$config,
  721. "other_config"=>$other_config,
  722. "weight"=>$weight,
  723. "good_weight"=>$good_weight,
  724. "is_diff"=>$is_diff,
  725. "demo_fee"=>$demo_fee,
  726. "delivery_fee"=>$delivery_fee,
  727. "open_fee"=>$open_fee,
  728. "pakge_fee"=>$pakge_fee,
  729. "nake_fee"=>$nake_fee,
  730. "mark_fee"=>$mark_fee,
  731. "cert_fee"=>$cert_fee,
  732. "cost_fee"=>$cost_fee,
  733. "total_fee"=>$total_fee,
  734. "supply_area"=>$supply_area,
  735. "remark"=>$remark,
  736. "sale_price"=>$saleprice,
  737. "sale_cost_fee"=>$sale_cost_fee,
  738. "origin_price"=>$saleprice,
  739. "createrid"=>$createrid,
  740. "creater"=>$creater,
  741. "status"=>$zxinfo['status']==1 ?1 :2,
  742. "is_del"=>0,
  743. "addtime"=>date("Y-m-d H:i:s"),
  744. "updatetime"=>date("Y-m-d H:i:s")
  745. ];
  746. Db::startTrans();
  747. try{
  748. $insert= Db::name("consult_bids")->insert($data);
  749. if($insert){
  750. // $data=[
  751. // "spuCode"=>$spucode,
  752. // "good_name"=>$pname,
  753. // "brand_id"=>$brandid,
  754. // "good_unit"=>$unit_id,
  755. // "good_type"=>0,
  756. // "moq"=>1,
  757. // "customized"=>$work_day,
  758. // "tax"=>$tax,
  759. // "supplierNo"=>$supplierNo,
  760. // "is_auth"=>0,
  761. // "craft_desc"=>$cost_desc,
  762. // "good_remark"=>$remark,
  763. // "good_img"=>$good_img,
  764. // "good_thumb_img"=>"",
  765. // "good_info_img"=>"",
  766. // "status"=>1,
  767. // "is_del"=>0,
  768. // "createrid"=>$createrid,
  769. // "creater"=>$creater,
  770. // "addtime"=>date("Y-m-d H:i:s"),
  771. // "updatetime"=>date("Y-m-d H:i:s")
  772. // ];
  773. // $good = Db::name("good_zixun")->insert($data);
  774. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  775. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  776. if($projectinfo==false){
  777. Db::rollback();
  778. return error_show(1006,"未找到项目信息");
  779. }
  780. $temp=[];
  781. $temp['spuCode']=$spucode;
  782. $temp['skuCode']="";
  783. $temp['pgNo']=$zxinfo['pgNo'];
  784. $temp['projectNo']=$zx['projectNo'];
  785. $temp['good_name']=$pname;
  786. $temp['good_type']=$projectinfo['good_type'];
  787. $temp['data_source']=2;
  788. $temp['cat_id']=$cat_id;
  789. $temp['budget_price']=$projectinfo['budget_price'];
  790. $temp['sale_price']=$saleprice;
  791. $temp['origin_price']=$total_fee;
  792. $temp['num']=$zxinfo['num'];
  793. $temp['status']=0;
  794. $temp['is_del']=0;
  795. $temp['creater']=$creater;
  796. $temp['createrid']=$createrid;
  797. $temp['addtime']=date("Y-m-d H:i:s");
  798. $temp['updatetime']=date("Y-m-d H:i:s");
  799. $nu = Db::name("project_feedback")->insert($temp);
  800. if($nu==false){
  801. Db::rollback();
  802. return error_show(1006,"项目反馈失败");
  803. }else{
  804. $old_projectinfo_status = $projectinfo['status'];
  805. $projectinfo['status']=2;
  806. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  807. $up = Db::name("project_info")->save($projectinfo);
  808. if($up){
  809. //修改状态,添加待办,只记录动作
  810. ActionLog::logAdd($this->post['token'], [
  811. "order_code" => $projectinfo['pgNo'],//编码
  812. "status" => $old_projectinfo_status,//这里的status是之前的值
  813. "action_remark" => '',//备注
  814. "action_type" => "status"//新建create,编辑edit,更改状态status
  815. ], "PRO", 2, $projectinfo);
  816. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  817. ->count();
  818. if($count==0){
  819. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  820. if($projetc!=false){
  821. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  822. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  823. if($proc==false){
  824. Db::rollback();
  825. return error_show(1006,"项目反馈失败");
  826. }else{
  827. //修改状态,添加待办
  828. ActionLog::logAdd($this->post['token'], [
  829. "order_code" => $projetc['projectNo'],//项目编码
  830. "status" => 1,//这里的status是之前的值
  831. "action_remark" => '',//备注
  832. "action_type" => "status"//新建create,编辑edit,更改状态status
  833. ], "PRO", 2, $projetc);
  834. ProcessOrder::AddProcess($this->post['token'], [
  835. "order_type" => 'PRO',
  836. "order_code" => $projetc['projectNo'],
  837. "order_id" => $projetc['id'],
  838. "order_status" => 2
  839. ]);
  840. }
  841. }
  842. }
  843. }
  844. }
  845. }
  846. Db::commit();
  847. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  848. }else{
  849. Db::rollback();
  850. return error_show(1006,"反馈失败");
  851. }
  852. }catch (\Exception $e){
  853. Db::rollback();
  854. return error_show(1006,$e->getMessage());
  855. }
  856. }
  857. public function feadinfo(){
  858. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  859. if($bidNo==""){
  860. return error_show(1004,"参数bidNo不能为空");
  861. }
  862. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  863. if($info==false){
  864. return error_show(1004,"未找到商品数据");
  865. }
  866. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  867. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  868. $info['cat_info'] = made($info['cat_id'],[]);
  869. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  870. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  871. if($info['brand_id']!=0){
  872. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  873. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  874. }else{
  875. $info["brand_name"]="";
  876. $info["brand_id"]="";
  877. }
  878. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  879. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  880. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  881. $god=[
  882. "metal_id"=>$info['metal_id'],
  883. "weight"=>$info["weight"],
  884. "demo_fee"=>$info["demo_fee"],
  885. "delivery_fee"=>$info["delivery_fee"],
  886. "open_fee"=>$info["open_fee"],
  887. "packing_fee"=>$info["pakge_fee"],
  888. "mark_fee"=>$info["mark_fee"],
  889. "nake_fee"=>$info["nake_fee"],
  890. "cert_fee"=>$info["cert_fee"],
  891. "cost_fee"=>$info["cost_fee"],
  892. "num"=>$bidinfo["num"],
  893. ];
  894. if($info['is_gold_price']==1){
  895. $price = GoldPrice($god, $budget/100);
  896. $info['sale_price'] =round($price,2);
  897. }
  898. $info['specinfo'] = json_decode($info['specinfo'],true);
  899. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  900. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  901. $info['bargain'] =$bargain;
  902. return app_show(0,"获取成功",$info);
  903. }
  904. public function feededit(){
  905. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  906. if($bidNo==""){
  907. return error_show(1002,"参数bidNo不能为空");
  908. }
  909. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  910. if($bidinfo==false){
  911. return error_show(1003,"未找到信息数据");
  912. }
  913. if($bidinfo['status']>=5){
  914. return error_show(1004,"咨询单已确认无法修改");
  915. }
  916. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  917. if($zxinfo==false){
  918. return error_show(1003,"未找到信息数据");
  919. }
  920. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  921. if($zx==false){
  922. return error_show(1003,"未找咨询信息数据");
  923. }
  924. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  925. if($pname==""){
  926. return error_show(1002,"参数pname不能为空");
  927. }
  928. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  929. // if($brandid==""){
  930. // return error_show(1002,"参数brandid不能为空");
  931. // }
  932. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  933. if($cat_id==""){
  934. return error_show(1002,"参数cat_id不能为空");
  935. }
  936. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  937. if($specin==""){
  938. return error_show(1003,"参数specinfo不能为空");
  939. }
  940. $specinfo=[];
  941. foreach ($specin as $v){
  942. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  943. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  944. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  945. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  946. $specinfo[]=$v;
  947. }
  948. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  949. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  950. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  951. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  952. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  953. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  954. :"";
  955. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  956. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  957. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  958. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  959. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  960. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  961. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  962. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  963. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  964. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  965. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  966. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  967. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  968. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  969. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  970. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  971. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  972. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  973. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  974. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  975. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  976. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  977. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  978. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  979. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  980. $cat_top_list = made($cat_id);
  981. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  982. if ($is_gold_price == 1 && $cat_top_id == 6) {
  983. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  984. ->find();
  985. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  986. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  987. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  988. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  989. $saleprice = $total_fee / (1 - $budget);
  990. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  991. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  992. }else{
  993. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee +
  994. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  995. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  996. }
  997. Db::startTrans();
  998. try{
  999. $data=[
  1000. "good_name"=>$pname,
  1001. "brand_id"=>$brandid,
  1002. "cat_id"=>$cat_id,
  1003. "specinfo"=>json_encode($specinfo),
  1004. // "material"=>$material,
  1005. "unit_id"=>$unit_id,
  1006. "cost_desc"=>$cost_desc,
  1007. "work_day"=>$work_day,
  1008. "delivery_day"=>$delivery_day,
  1009. "good_img"=>$good_img,
  1010. "expire_day"=>$expire_day,
  1011. "origin_place"=>$origin_place,
  1012. "supplierNo"=>$supplierNo,
  1013. "pay_way"=>$pay_way,
  1014. "tax"=>$tax,
  1015. "send_way"=>$send_way,
  1016. "metal_id"=>$metal_id,
  1017. "is_gold_price"=>$is_gold_price,
  1018. "config"=>$config,
  1019. "other_config"=>$other_config,
  1020. "weight"=>$weight,
  1021. "is_diff"=>$is_diff,
  1022. "demo_fee"=>$demo_fee,
  1023. "delivery_fee"=>$delivery_fee,
  1024. "open_fee"=>$open_fee,
  1025. "pakge_fee"=>$pakge_fee,
  1026. "nake_fee"=>$nake_fee,
  1027. "mark_fee"=>$mark_fee,
  1028. "cert_fee"=>$cert_fee,
  1029. "cost_fee"=>$cost_fee,
  1030. "sale_cost_fee"=>$sale_cost_fee,
  1031. "total_fee"=>$total_fee,
  1032. "sale_price"=>$saleprice,
  1033. "supply_area"=>$supply_area,
  1034. "remark"=>$remark,
  1035. "updatetime"=>date("Y-m-d H:i:s")
  1036. ];
  1037. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1038. if($insert){
  1039. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1040. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1041. if($projectinfo==false){
  1042. Db::rollback();
  1043. return error_show(1006,"未找到项目信息");
  1044. }
  1045. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1046. if($feed==false){
  1047. Db::rollback();
  1048. return error_show(1006,"未找到项目反馈信息");
  1049. }
  1050. $feed['good_name']=$pname;
  1051. $feed['good_type']=$projectinfo['good_type'];
  1052. $feed['cat_id']=$cat_id;
  1053. $feed['sale_price']=$saleprice;
  1054. $feed['origin_price']=$total_fee;
  1055. $feed['updatetime']=date("Y-m-d H:i:s");
  1056. $temp['updatetime']=date("Y-m-d H:i:s");
  1057. $nu = Db::name("project_feedback")->save($feed);
  1058. if($nu==false){
  1059. Db::rollback();
  1060. return error_show(1006,"项目反馈失败");
  1061. }else{
  1062. $old_projectinfo_status = $projectinfo['status'];
  1063. $projectinfo['status']=2;
  1064. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1065. $up = Db::name("project_info")->save($projectinfo);
  1066. if($up){
  1067. //修改状态,添加待办,只记录动作
  1068. ActionLog::logAdd($this->post['token'], [
  1069. "order_code" => $projectinfo['pgNo'],//编码
  1070. "status" => $old_projectinfo_status,//这里的status是之前的值
  1071. "action_remark" => '',//备注
  1072. "action_type" => "status"//新建create,编辑edit,更改状态status
  1073. ], "PRO", 2, $projectinfo);
  1074. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1075. if ($count == 0) {
  1076. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1077. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1078. if ($project_id) {
  1079. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1080. if ($proc == false) {
  1081. Db::rollback();
  1082. return error_show(1006, "项目反馈失败");
  1083. }else{
  1084. //修改状态,添加待办
  1085. ActionLog::logAdd($this->post['token'], [
  1086. "order_code" => $projectinfo['projectNo'],//项目编码
  1087. "status" => 1,//这里的status是之前的值
  1088. "action_remark" => '',//备注
  1089. "action_type" => "status"//新建create,编辑edit,更改状态status
  1090. ], "PRO", 2, $this->post);
  1091. ProcessOrder::AddProcess($this->post['token'], [
  1092. "order_type" => 'PRO',
  1093. "order_code" => $projectinfo['projectNo'],
  1094. "order_id" => $project_id,
  1095. "order_status" => 2
  1096. ]);
  1097. }
  1098. }
  1099. }
  1100. }
  1101. }
  1102. }
  1103. Db::commit();
  1104. return app_show(0,"编辑成功");
  1105. }else{
  1106. Db::rollback();
  1107. return error_show(1004,"编辑失败");
  1108. }
  1109. }catch (\Exception $e){
  1110. Db::rollback();
  1111. return error_show(1004,$e->getMessage());
  1112. }
  1113. }
  1114. public function bargain_add(){
  1115. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1116. if($bidNo===""){
  1117. return error_show(1004,"参数bidNo不能为空");
  1118. }
  1119. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1120. if($info==false){
  1121. return error_show(1004,"未找到商品数据");
  1122. }
  1123. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1124. if($consult==false){
  1125. return error_show(1004,"未找到咨询数据");
  1126. }
  1127. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1128. if($bargain_price===""){
  1129. return error_show(1004,"参数bargain_price不能为空");
  1130. }
  1131. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1132. if($info['is_gold_price']==1){
  1133. if($cost_price==""){
  1134. return error_show(1004,"参数cost_price不能为空");
  1135. }
  1136. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1137. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1138. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1139. ->find();
  1140. $bargain_price = ($info['demo_fee'] / $consult['num']+$info['delivery_fee']+$info['open_fee'] /$consult['num'] +
  1141. $info['weight'] * $gold["price"] + $cost_price *$info['weight'] + $info['pakge_fee'] + $info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1142. }
  1143. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1144. // if($bargain_reason===""){
  1145. // return error_show(1004,"参数bargain_reason不能为空");
  1146. // }
  1147. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1148. if($infos==false){
  1149. return error_show(1004,"未找到商品数据");
  1150. }
  1151. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1152. return error_show(1004,"咨询单招标未结束或已确认商品");
  1153. }
  1154. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1155. if($token==''){
  1156. return error_show(105,"参数token不能为空");
  1157. }
  1158. $user =GetUserInfo($token);
  1159. if(empty($user)||$user['code']!=0){
  1160. return error_show(1002,"用户数据不存在");
  1161. }
  1162. //新增两个字段
  1163. //议价备注
  1164. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1165. //议价原因id
  1166. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1167. if ($result_info_id != '') {
  1168. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1169. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1170. }
  1171. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1172. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1173. $bargainNo =makeNo("BA");
  1174. Db::startTrans();//::todo 金价 毛利计算
  1175. try{
  1176. $data=[
  1177. "bidsNo"=>$bidNo,
  1178. "infoNo"=>$info['infoNo'],
  1179. "zxNo"=>$info['zxNo'],
  1180. "bargainNo"=>$bargainNo,
  1181. "bargain_type"=>1,
  1182. "bargain_reason"=>$bargain_reason,
  1183. "sale_price"=>$info['sale_price'],
  1184. "cost_before_price"=>$info['cost_fee'],
  1185. "cost_after_price"=>$cost_price,
  1186. "before_rate"=>round(($info['sale_price']-$info['total_fee'])/$info['sale_price'],2),
  1187. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1188. "after_price"=>$bargain_price,
  1189. "exam_info"=>"",
  1190. "status"=>0,
  1191. "is_del"=>0,
  1192. "creater"=>$creater,
  1193. "createrid"=>$createrid,
  1194. "addtime"=>date("Y-m-d H:i:s"),
  1195. "updatetime"=>date("Y-m-d H:i:s"),
  1196. 'bargain_remark'=>$bargain_remark,
  1197. 'result_info_id'=>$result_info_id,
  1198. ];
  1199. $int = Db::name("bargain_order")->insert($data);
  1200. if($int){
  1201. $info['status']=3;
  1202. $info['updatetime']=date("Y-m-d H:i:s");
  1203. $up =Db::name("consult_bids")->save($info);
  1204. if($up){
  1205. $old_infos_status = $infos['status'];
  1206. $infos['status']=3;
  1207. $infos['updatetime']=date("Y-m-d H:i:s");
  1208. $ups =Db::name("consult_info")->save($infos);
  1209. if($ups){
  1210. //修改状态,添加待办
  1211. ActionLog::logAdd($this->post['token'], [
  1212. "order_code" => $infos['infoNo'],//咨询单详情编号
  1213. "status" => $old_infos_status,//这里的status是之前的值
  1214. "action_remark" => '',//备注
  1215. "action_type" => "status"//新建create,编辑edit,更改状态status
  1216. ], "ZXD", $infos['status'], $infos);
  1217. ProcessOrder::AddProcess($this->post['token'], [
  1218. "order_type" => 'ZXD',
  1219. "order_code" => $infos['infoNo'],//咨询单详情编号
  1220. "order_id" => $infos['id'],
  1221. "order_status" => $infos['status']
  1222. ]);
  1223. Db::commit();
  1224. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1225. }
  1226. }
  1227. }
  1228. Db::rollback();
  1229. return error_show(1004,"议价单新建失败");
  1230. }catch (\Exception $e){
  1231. Db::rollback();
  1232. return error_show(1004,$e->getMessage());
  1233. }
  1234. }
  1235. //选择商品
  1236. public function bids_check(){
  1237. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1238. if($bidNo===""){
  1239. return error_show(1004,"参数bidNo不能为空");
  1240. }
  1241. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1242. if($info==false){
  1243. return error_show(1004,"未找到商品数据");
  1244. }
  1245. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1246. if($infos==false){
  1247. return error_show(1004,"未找到商品数据");
  1248. }
  1249. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1250. return error_show(1004,"咨询单招标未结束或已确认商品");
  1251. }
  1252. Db::startTrans();
  1253. try {
  1254. $info['status']=6;
  1255. $info['updatetime']=date("Y-m-d H:i:s");
  1256. $bids = Db::name("consult_bids")->save($info);
  1257. if($bids){
  1258. $old_infos_status = $infos['status'];
  1259. $infos['status']=4;
  1260. $infos['updatetime']=date("Y-m-d H:i:s");
  1261. $se = Db::name("consult_info")->save($infos);
  1262. if($se){
  1263. //修改状态,添加待办
  1264. ActionLog::logAdd($this->post['token'], [
  1265. "order_code" => $infos['infoNo'],//咨询单详情编号
  1266. "status" => $old_infos_status,//这里的status是之前的值
  1267. "action_remark" => '',//备注
  1268. "action_type" => "status"//新建create,编辑edit,更改状态status
  1269. ], "ZXD", $infos['status'], $infos);
  1270. ProcessOrder::AddProcess($this->post['token'], [
  1271. "order_type" => 'ZXD',
  1272. "order_code" => $infos['infoNo'],//咨询单详情编号
  1273. "order_id" => $infos['id'],
  1274. "order_status" => $infos['status']
  1275. ]);
  1276. Db::commit();
  1277. return app_show(0,"商品确定成功");
  1278. }
  1279. }
  1280. Db::rollback();
  1281. return error_show(1004,"商品确认失败");
  1282. }catch (\Exception $e){
  1283. Db::rollback();
  1284. return error_show(1004,$e->getMessage());
  1285. }
  1286. }
  1287. //议价审核
  1288. /**
  1289. * status:
  1290. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1291. */
  1292. public function bargain_status(){
  1293. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1294. if($bargainNo===""){
  1295. return error_show(1004,"参数bargainNo不能为空");
  1296. }
  1297. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1298. if($info==false){
  1299. return error_show(1004,"未找到议价数据");
  1300. }
  1301. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1302. if($bids==false){
  1303. return error_show(1004,"未找到商品数据");
  1304. }
  1305. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1306. if($coninfo==false){
  1307. return error_show(1004,"未找到咨询单数据");
  1308. }
  1309. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1310. if($status===''){
  1311. return error_show(1005,"参数status不能为空");
  1312. }
  1313. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1314. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1315. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1316. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1317. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1318. if($bids['is_gold_price']==1){
  1319. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1320. ->find();
  1321. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1322. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1323. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1324. $bids['weight']*$gold["price"] +$bids['cost_fee']*$bids['weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1325. $saleprice =$total_fe / (1 - $budget);
  1326. $rate_price = $total_fe / (1 - $rate);
  1327. $money_price =$total_fe / (1 - $money_rate);
  1328. $lower_price =$total_fe / (1 - $lower_rate);
  1329. }else{
  1330. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1331. $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1332. if($bids['nake_fee']!=0){
  1333. $saleprice = ($total_fe)/ (1 - $budget);
  1334. $rate_price = ($total_fe)/ (1 - $rate);
  1335. $money_price =($total_fe)/ (1 - $money_rate);
  1336. $lower_price = ($total_fe) / (1 - $lower_rate);
  1337. }else{
  1338. $saleprice = $total_fe / (1 - $budget);
  1339. $rate_price =$total_fe/ (1 - $rate);
  1340. $money_price =$total_fe / (1 - $money_rate);
  1341. $lower_price = $total_fe/ (1 - $lower_rate);
  1342. }
  1343. }
  1344. $ra_status = $info['status'];
  1345. if($status==1){
  1346. if($info['status']==0){
  1347. if($info['after_price']<$rate_price){
  1348. $info['status']=2;
  1349. }else{
  1350. $info['status']=1;
  1351. }
  1352. }elseif($info['status']==2){
  1353. $info['status']=4;
  1354. }elseif($info['status']==4||$info['status']==5){
  1355. if($info['after_price']<$money_price){
  1356. $info['status']=7;
  1357. }else{
  1358. $info['status']=6;
  1359. }
  1360. }elseif($info['status']==7){
  1361. $info['lower_price'] =$lower_price;
  1362. if($info['after_price']<$lower_price){
  1363. $info['status']=10;
  1364. }else{
  1365. $info['status']=9;
  1366. }
  1367. }
  1368. }else{
  1369. if($info['status']==0){
  1370. $info['status']=3;
  1371. }elseif($info['status']==2){
  1372. $info['status']=4;
  1373. }elseif($info['status']==4||$info['status']==5){
  1374. $info['status']=8;
  1375. }elseif($info['status']==7){
  1376. $info['lower_price'] =$lower_price;
  1377. $info['status']=11;
  1378. }
  1379. }
  1380. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1381. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1382. if($token==''){
  1383. return error_show(105,"参数token不能为空");
  1384. }
  1385. $user =GetUserInfo($token);
  1386. if(empty($user)||$user['code']!=0){
  1387. return error_show(1002,"用户数据不存在");
  1388. }
  1389. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1390. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1391. Db::startTrans();
  1392. try{
  1393. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1394. $examinfo[]=["status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1395. // $info['status'] =$status;
  1396. $info['remark'] =$remark;
  1397. $info['exam_info']=json_encode($examinfo) ;
  1398. $info['updatetime'] =date("Y-m-d H:i:s");
  1399. $up =Db::name("bargain_order")->save($info);
  1400. if($up){
  1401. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1402. $bids['status']=5;
  1403. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1404. $bids['sale_price']=$info['after_price'];
  1405. if($bids['is_gold_price']==1){
  1406. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1407. // ->find();
  1408. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1409. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1410. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1411. }
  1412. }
  1413. $bids['updatetime']=date("Y-m-d H:i:s");
  1414. $up =Db::name("consult_bids")->save($bids);
  1415. if($up==false){
  1416. Db::rollback();
  1417. return error_show(1004,"数据更新失败");
  1418. }
  1419. }
  1420. Db::commit();
  1421. return app_show(0,"更新成功");
  1422. }
  1423. }catch (\Exception $e){
  1424. Db::rollback();
  1425. return error_show(1004,$e->getMessage());
  1426. }
  1427. }
  1428. public function bargain_info(){
  1429. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1430. if($bargainNo===""){
  1431. return error_show(1004,"参数bargainNo不能为空");
  1432. }
  1433. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1434. if($info==false){
  1435. return error_show(1004,"未找到议价数据");
  1436. }
  1437. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1438. if($bidinfos==false){
  1439. return error_show(1004,"未找到商品数据");
  1440. }
  1441. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1442. ->find();
  1443. if($consultinfos==false){
  1444. return error_show(1004,"未找到咨询商品数据");
  1445. }
  1446. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1447. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1448. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1449. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1450. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1451. $info['before_rate'] =round($info['before_rate']*100,2);
  1452. $info['after_rate'] = round($info['after_rate']*100,2);
  1453. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1454. if($bidinfos['brand_id']!=0){
  1455. $info['brand_id'] = $bidinfos['brand_id'];
  1456. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1457. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1458. }else{
  1459. $info["brand_name"]="";
  1460. $info["brand_id"]="";
  1461. }
  1462. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1463. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1464. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1465. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1466. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1467. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1468. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1469. $info['budget'] =$budget;
  1470. $god=[
  1471. "metal_id"=>$bidinfos['metal_id'],
  1472. "weight"=>$bidinfos["weight"],
  1473. "demo_fee"=>$bidinfos["demo_fee"],
  1474. "delivery_fee"=>$bidinfos["delivery_fee"],
  1475. "open_fee"=>$bidinfos["open_fee"],
  1476. "packing_fee"=>$bidinfos["pakge_fee"],
  1477. "mark_fee"=>$bidinfos["mark_fee"],
  1478. "nake_fee"=>$bidinfos["nake_fee"],
  1479. "cert_fee"=>$bidinfos["cert_fee"],
  1480. "cost_fee"=>$bidinfos["cost_fee"],
  1481. "num"=>$bidinfoe["num"],
  1482. ];
  1483. $info['gold_price']=0;
  1484. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1485. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1486. ->find();
  1487. $info['gold_price'] =$gold['price'];
  1488. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee'] /
  1489. $consultinfos['num'] + $bidinfos['weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1490. }else{
  1491. if($bidinfos['nake_fee']!=0){
  1492. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1493. }else{
  1494. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos
  1495. ['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1496. }
  1497. }
  1498. $info['cost_desc'] =$bidinfos['cost_desc'];
  1499. $info['work_day'] =$bidinfos['work_day'];
  1500. $info['delivery_day'] =$bidinfos['delivery_day'];
  1501. $info['expire_day'] =$bidinfos['expire_day'];
  1502. $info['origin_place'] =$bidinfos['origin_place'];
  1503. $info['origin_addr'] ="";
  1504. if($bidinfos['origin_place']!=''){
  1505. $code = explode(",",$bidinfos['origin_place']);
  1506. $temp=[];
  1507. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1508. $temp['city_code']=isset($code[1])?$code[1]:"";
  1509. $temp['area_code']=isset($code[2])?$code[2]:"";
  1510. $addr= GetAddr(json_encode($temp));
  1511. $info['origin_addr'] = $addr;
  1512. }
  1513. $info['supplierNo'] =$bidinfos['supplierNo'];
  1514. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1515. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1516. $info['pay_way'] =$bidinfos['pay_way'];
  1517. $info['tax'] =$bidinfos['tax'];
  1518. $info['send_way'] =$bidinfos['send_way'];
  1519. $info['metal_id'] =$bidinfos['metal_id'];
  1520. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1521. $info['config'] =$bidinfos['config'];
  1522. $info['other_config'] =$bidinfos['other_config'];
  1523. $info['weight'] =$bidinfos['weight'];
  1524. $info['is_diff'] =$bidinfos['is_diff'];
  1525. $info['demo_fee'] =$bidinfos['demo_fee'];
  1526. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1527. $info['open_fee'] =$bidinfos['open_fee'];
  1528. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1529. $info['nake_fee'] =$bidinfos['nake_fee'];
  1530. $info['mark_fee'] =$bidinfos['mark_fee'];
  1531. $info['cert_fee'] =$bidinfos['cert_fee'];
  1532. $info['cost_fee'] =$bidinfos['cost_fee'];
  1533. $info['total_fee'] =$bidinfos['total_fee'];
  1534. $info['supply_area'] =$bidinfos['supply_area'];
  1535. $info['remark'] =$bidinfos['remark'];
  1536. $info['is_addrs'] =$consultinfos['is_addrs'];
  1537. $info['is_custom'] =$consultinfos['is_custom'];
  1538. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1539. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1540. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1541. if($info['status']==7){
  1542. $info['lower_price'] =round($lower_price,2);
  1543. }
  1544. //获取议价原因
  1545. if ($info['result_info_id'] != 0) {
  1546. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1547. } else {
  1548. $info['result_info'] = '';
  1549. }
  1550. return app_show(0,"获取成功",$info);
  1551. }
  1552. public function bidlist(){
  1553. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1554. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1555. $where=[['is_del',"=",0]];
  1556. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1557. if ($zxNo !== "") {
  1558. $where[] = ['zxNo','=',$zxNo];
  1559. }
  1560. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1561. if ($infoNo !== "") {
  1562. $where[] = ['infoNo','=',$infoNo];
  1563. }
  1564. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1565. if ($bidNo !== "") {
  1566. $where[] = ['bidNo','=',$bidNo];
  1567. }
  1568. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1569. if ($pgNo !== "") {
  1570. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1571. $where[] = ['infoNo','in',$bidinfo];
  1572. }
  1573. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1574. if ($bargain_status !== "") {
  1575. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1576. $where[] = ['infoNo','in',$bidinfo];
  1577. }
  1578. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1579. if ($projectNo !== "") {
  1580. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1581. ("zxNo");
  1582. $where[] = ['zxNo','in',$zxlist];
  1583. }
  1584. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1585. if($is_own==1){
  1586. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1587. if($token==""){
  1588. return error_show(101,'token不能为空');
  1589. }
  1590. $apply_id =GetUserInfo($token);
  1591. if(empty($apply_id)||$apply_id['code']!=0){
  1592. return error_show(1002,"申请人数据不存在");
  1593. }
  1594. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1595. $where[]=['createrid',"=",$rm];
  1596. }
  1597. $count = Db::name('consult_bids')->where($where)->count();
  1598. $total = ceil($count / $size);
  1599. $page = $page >= $total ? $total : $page;
  1600. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1601. $data=[];
  1602. foreach ($list as $value){
  1603. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1604. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1605. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1606. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1607. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1608. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1609. if($value['brand_id']!=0){
  1610. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1611. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1612. }else{
  1613. $value["brand_name"]="";
  1614. $value["brand_id"]="";
  1615. }
  1616. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1617. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1618. $god=[
  1619. "metal_id"=>$value['metal_id'],
  1620. "weight"=>$value["weight"],
  1621. "demo_fee"=>$value["demo_fee"],
  1622. "delivery_fee"=>$value["delivery_fee"],
  1623. "open_fee"=>$value["open_fee"],
  1624. "packing_fee"=>$value["pakge_fee"],
  1625. "mark_fee"=>$value["mark_fee"],
  1626. "nake_fee"=>$value["nake_fee"],
  1627. "cert_fee"=>$value["cert_fee"],
  1628. "cost_fee"=>$value["cost_fee"],
  1629. "num"=>$bidinfo["num"],
  1630. ];
  1631. if($value['is_gold_price']==1){
  1632. $price = GoldPrice($god, $budget/100);
  1633. $value['sale_price'] = round($price,2);
  1634. }
  1635. $value['specinfo'] = json_decode($value['specinfo'],true);
  1636. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1637. $value['bargain_status']=$bidinfo['bargain_status'];
  1638. //reject驳回原因,status==5表示驳回
  1639. $value['reject']=[];
  1640. if ($value['status'] == 5) {
  1641. $value['reject'] = Db::name('bargain_order')
  1642. ->field('id,remark,status')
  1643. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1644. ->whereIn('status', [5, 6])
  1645. ->find();
  1646. }
  1647. //产地
  1648. if($value['origin_place']!=''){
  1649. $code = explode(",",$value['origin_place']);
  1650. $temp=[];
  1651. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1652. $temp['city_code']=isset($code[1])?$code[1]:"";
  1653. $temp['area_code']=isset($code[2])?$code[2]:"";
  1654. $addr= GetAddr(json_encode($temp));
  1655. $value['origin_addr'] = $addr;
  1656. }
  1657. $data[] = $value;
  1658. }
  1659. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1660. }
  1661. public function feedlist(){
  1662. $where=[['is_del',"=",0]];
  1663. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1664. if ($zxNo !== "") {
  1665. $where[] = ['zxNo','=',$zxNo];
  1666. }
  1667. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1668. if ($infoNo !== "") {
  1669. $where[] = ['infoNo','=',$infoNo];
  1670. }
  1671. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1672. if ($bidNo !== "") {
  1673. $where[] = ['bidNo','=',$bidNo];
  1674. }
  1675. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1676. if ($projectNo !== "") {
  1677. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1678. ("zxNo");
  1679. $where[] = ['zxNo','in',$zxlist];
  1680. }
  1681. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1682. if($token==''){
  1683. return error_show(102,"参数token不能为空");
  1684. }
  1685. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1686. if($is_own==1){
  1687. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1688. if($token==""){
  1689. return error_show(101,'token不能为空');
  1690. }
  1691. $apply_id =GetUserInfo($token);
  1692. if(empty($apply_id)||$apply_id['code']!=0){
  1693. return error_show(1002,"申请人数据不存在");
  1694. }
  1695. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1696. $where[]=['createrid',"=",$rm];
  1697. }
  1698. $list =Db::name('consult_bids')->where($where)->select();
  1699. $data=[];
  1700. foreach ($list as $value){
  1701. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1702. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1703. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1704. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1705. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1706. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1707. if($value['brand_id']!=0){
  1708. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1709. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1710. }else{
  1711. $value["brand_name"]="";
  1712. $value["brand_id"]="";
  1713. }
  1714. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1715. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1716. $god=[
  1717. "metal_id"=>$value['metal_id'],
  1718. "weight"=>$value["weight"],
  1719. "demo_fee"=>$value["demo_fee"],
  1720. "delivery_fee"=>$value["delivery_fee"],
  1721. "open_fee"=>$value["open_fee"],
  1722. "packing_fee"=>$value["pakge_fee"],
  1723. "mark_fee"=>$value["mark_fee"],
  1724. "nake_fee"=>$value["nake_fee"],
  1725. "cert_fee"=>$value["cert_fee"],
  1726. "cost_fee"=>$value["cost_fee"],
  1727. "num"=>$bidinfo["num"],
  1728. ];
  1729. if ($value['is_gold_price'] == 1 ) {
  1730. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1731. ->find();
  1732. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1733. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1734. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["weight"] *$gold["price"] +
  1735. $value["cost_fee"] * $value["weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1736. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1737. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1738. }else{
  1739. if($value["nake_fee"]){
  1740. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1741. }else{
  1742. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1743. (1 - $budget);
  1744. }
  1745. }
  1746. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1747. $value['specinfo'] = json_decode($value['specinfo'],true);
  1748. $value['bargain_status']=$bidinfo['bargain_status'];
  1749. $data[]=$value;
  1750. }
  1751. return app_show(0,"获取成功",$data);
  1752. }
  1753. public function bragain_list(){
  1754. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1755. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1756. $where=[['is_del',"=",0]];
  1757. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1758. if($bidsNo!=""){
  1759. $where[]=["bidsNo","=",$bidsNo];
  1760. }
  1761. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1762. if ($zxNo !== "") {
  1763. $where[] = ['zxNo','=',$zxNo];
  1764. }
  1765. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1766. if ($infoNo !== "") {
  1767. $where[] = ['infoNo','=',$infoNo];
  1768. }
  1769. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1770. if ($projectNo !== "") {
  1771. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1772. ("zxNo");
  1773. $where[] = ['zxNo','in',$zxlist];
  1774. }
  1775. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1776. if ($pgNo !== "") {
  1777. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1778. $where[] = ['infoNo','in',$bidinfo];
  1779. }
  1780. $count=Db::name("bargain_order")->where($where)->count();
  1781. $total = ceil($count / $size);
  1782. $page = $page >= $total ? $total : $page;
  1783. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1784. $data=[];
  1785. foreach ($list as $value){
  1786. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1787. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1788. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1789. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1790. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1791. if($bidinfos['brand_id']!=0){
  1792. $value['brand_id'] = $bidinfos['brand_id'];
  1793. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1794. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1795. }else{
  1796. $value["brand_name"]="";
  1797. $value["brand_id"]="";
  1798. }
  1799. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1800. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1801. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1802. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1803. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1804. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1805. $value['budget'] =$budget;
  1806. $god=[
  1807. "metal_id"=>$bidinfos['metal_id'],
  1808. "weight"=>$bidinfos["weight"],
  1809. "demo_fee"=>$bidinfos["demo_fee"],
  1810. "delivery_fee"=>$bidinfos["delivery_fee"],
  1811. "open_fee"=>$bidinfos["open_fee"],
  1812. "packing_fee"=>$bidinfos["pakge_fee"],
  1813. "mark_fee"=>$bidinfos["mark_fee"],
  1814. "nake_fee"=>$bidinfos["nake_fee"],
  1815. "cert_fee"=>$bidinfos["cert_fee"],
  1816. "cost_fee"=>$bidinfos["cost_fee"],
  1817. "num"=>$bidinfoe["num"],
  1818. ];
  1819. // if($bidinfos['is_gold_price']==1){
  1820. // $price = GoldPrice($god, $budget/100);
  1821. // }else{
  1822. // $price = GoodPrice($god, $budget/100);
  1823. // }
  1824. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1825. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1826. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1827. $data[]=$value;
  1828. }
  1829. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1830. }
  1831. public function crontablist(){
  1832. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1833. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1834. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1835. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1836. if ($zxNo !== "") {
  1837. $where[] = ['a.zxNo','=',$zxNo];
  1838. }
  1839. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1840. if ($salesman !== "") {
  1841. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1842. $where[]= ["b.salesman",'like',"%$salesman%"];
  1843. }
  1844. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1845. if ($cpName !== "") {
  1846. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1847. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1848. }
  1849. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1850. if ($khNo !== "") {
  1851. // $where['khNo'] = $khNo;
  1852. $where[]= ["b.khNo",'like',"%$khNo%"];
  1853. }
  1854. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1855. if ($start !="") {
  1856. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1857. $where[]= ["a.addtime",'>=',$start];
  1858. }
  1859. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1860. if($end !=""){
  1861. $where[]= ["a.addtime",'<=',$end];
  1862. }
  1863. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1864. if ($status !== "") {
  1865. $where[]= ["a.status",'=',$status];
  1866. }
  1867. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1868. ->count();
  1869. $total = ceil($count / $size);
  1870. $page = $page >= $total ? $total : $page;
  1871. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1872. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1873. $data=[];
  1874. foreach ($list as $value){
  1875. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1876. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1877. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1878. $value['khname']="";
  1879. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1880. true):[];
  1881. if($value['khNo']!==""){
  1882. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1883. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1884. }
  1885. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1886. $data[]=$value;
  1887. }
  1888. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1889. }
  1890. }