Consult.php 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  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. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  685. $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"];
  686. }else{
  687. if($nake_fee){
  688. $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee +
  689. $nake_fee)/ (1 - $budget);
  690. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  691. }else{
  692. $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee) /
  693. (1 - $budget);
  694. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee;
  695. }
  696. }
  697. $data=[
  698. "bidNo"=>$bidNo,
  699. "infoNo"=>$infoNo,
  700. "zxNo"=>$zxinfo['zxNo'],
  701. "spuCode"=>$spucode,
  702. "good_name"=>$pname,
  703. "brand_id"=>$brandid,
  704. "cat_id"=>$cat_id,
  705. "specinfo"=>json_encode($specinfo),
  706. "unit_id"=>$unit_id,
  707. "cost_desc"=>$cost_desc,
  708. "work_day"=>$work_day,
  709. "delivery_day"=>$delivery_day,
  710. "good_img"=>$good_img,
  711. "expire_day"=>$expire_day,
  712. "origin_place"=>$origin_place,
  713. "supplierNo"=>$supplierNo,
  714. "pay_way"=>$pay_way,
  715. "tax"=>$tax,
  716. "send_way"=>$send_way,
  717. "metal_id"=>$metal_id,
  718. "is_gold_price"=>$is_gold_price,
  719. "config"=>$config,
  720. "other_config"=>$other_config,
  721. "weight"=>$weight,
  722. "good_weight"=>$good_weight,
  723. "is_diff"=>$is_diff,
  724. "demo_fee"=>$demo_fee,
  725. "delivery_fee"=>$delivery_fee,
  726. "open_fee"=>$open_fee,
  727. "pakge_fee"=>$pakge_fee,
  728. "nake_fee"=>$nake_fee,
  729. "mark_fee"=>$mark_fee,
  730. "cert_fee"=>$cert_fee,
  731. "cost_fee"=>$cost_fee,
  732. "total_fee"=>$total_fee,
  733. "supply_area"=>$supply_area,
  734. "remark"=>$remark,
  735. "sale_price"=>$saleprice,
  736. "sale_cost_fee"=>$sale_cost_fee,
  737. "origin_price"=>$saleprice,
  738. "createrid"=>$createrid,
  739. "creater"=>$creater,
  740. "status"=>$zxinfo['status']==1 ?1 :2,
  741. "is_del"=>0,
  742. "addtime"=>date("Y-m-d H:i:s"),
  743. "updatetime"=>date("Y-m-d H:i:s")
  744. ];
  745. Db::startTrans();
  746. try{
  747. $insert= Db::name("consult_bids")->insert($data);
  748. if($insert){
  749. // $data=[
  750. // "spuCode"=>$spucode,
  751. // "good_name"=>$pname,
  752. // "brand_id"=>$brandid,
  753. // "good_unit"=>$unit_id,
  754. // "good_type"=>0,
  755. // "moq"=>1,
  756. // "customized"=>$work_day,
  757. // "tax"=>$tax,
  758. // "supplierNo"=>$supplierNo,
  759. // "is_auth"=>0,
  760. // "craft_desc"=>$cost_desc,
  761. // "good_remark"=>$remark,
  762. // "good_img"=>$good_img,
  763. // "good_thumb_img"=>"",
  764. // "good_info_img"=>"",
  765. // "status"=>1,
  766. // "is_del"=>0,
  767. // "createrid"=>$createrid,
  768. // "creater"=>$creater,
  769. // "addtime"=>date("Y-m-d H:i:s"),
  770. // "updatetime"=>date("Y-m-d H:i:s")
  771. // ];
  772. // $good = Db::name("good_zixun")->insert($data);
  773. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  774. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  775. if($projectinfo==false){
  776. Db::rollback();
  777. return error_show(1006,"未找到项目信息");
  778. }
  779. $temp=[];
  780. $temp['spuCode']=$spucode;
  781. $temp['skuCode']="";
  782. $temp['pgNo']=$zxinfo['pgNo'];
  783. $temp['projectNo']=$zx['projectNo'];
  784. $temp['good_name']=$pname;
  785. $temp['good_type']=$projectinfo['good_type'];
  786. $temp['data_source']=2;
  787. $temp['cat_id']=$cat_id;
  788. $temp['budget_price']=$projectinfo['budget_price'];
  789. $temp['sale_price']=$saleprice;
  790. $temp['origin_price']=$total_fee;
  791. $temp['num']=$zxinfo['num'];
  792. $temp['status']=0;
  793. $temp['is_del']=0;
  794. $temp['creater']=$creater;
  795. $temp['createrid']=$createrid;
  796. $temp['addtime']=date("Y-m-d H:i:s");
  797. $temp['updatetime']=date("Y-m-d H:i:s");
  798. $nu = Db::name("project_feedback")->insert($temp);
  799. if($nu==false){
  800. Db::rollback();
  801. return error_show(1006,"项目反馈失败");
  802. }else{
  803. $old_projectinfo_status = $projectinfo['status'];
  804. $projectinfo['status']=2;
  805. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  806. $up = Db::name("project_info")->save($projectinfo);
  807. if($up){
  808. //修改状态,添加待办,只记录动作
  809. ActionLog::logAdd($this->post['token'], [
  810. "order_code" => $projectinfo['pgNo'],//编码
  811. "status" => $old_projectinfo_status,//这里的status是之前的值
  812. "action_remark" => '',//备注
  813. "action_type" => "status"//新建create,编辑edit,更改状态status
  814. ], "PRO", 2, $projectinfo);
  815. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  816. ->count();
  817. if($count==0){
  818. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  819. if($projetc!=false){
  820. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  821. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  822. if($proc==false){
  823. Db::rollback();
  824. return error_show(1006,"项目反馈失败");
  825. }else{
  826. //修改状态,添加待办
  827. ActionLog::logAdd($this->post['token'], [
  828. "order_code" => $projetc['projectNo'],//项目编码
  829. "status" => 1,//这里的status是之前的值
  830. "action_remark" => '',//备注
  831. "action_type" => "status"//新建create,编辑edit,更改状态status
  832. ], "PRO", 2, $projetc);
  833. ProcessOrder::AddProcess($this->post['token'], [
  834. "order_type" => 'PRO',
  835. "order_code" => $projetc['projectNo'],
  836. "order_id" => $projetc['id'],
  837. "order_status" => 2
  838. ]);
  839. }
  840. }
  841. }
  842. }
  843. }
  844. }
  845. Db::commit();
  846. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  847. }else{
  848. Db::rollback();
  849. return error_show(1006,"反馈失败");
  850. }
  851. }catch (\Exception $e){
  852. Db::rollback();
  853. return error_show(1006,$e->getMessage());
  854. }
  855. }
  856. public function feadinfo(){
  857. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  858. if($bidNo==""){
  859. return error_show(1004,"参数bidNo不能为空");
  860. }
  861. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  862. if($info==false){
  863. return error_show(1004,"未找到商品数据");
  864. }
  865. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  866. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  867. $info['cat_info'] = made($info['cat_id'],[]);
  868. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  869. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  870. if($info['brand_id']!=0){
  871. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  872. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  873. }else{
  874. $info["brand_name"]="";
  875. $info["brand_id"]="";
  876. }
  877. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  878. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  879. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  880. $god=[
  881. "metal_id"=>$info['metal_id'],
  882. "weight"=>$info["weight"],
  883. "demo_fee"=>$info["demo_fee"],
  884. "delivery_fee"=>$info["delivery_fee"],
  885. "open_fee"=>$info["open_fee"],
  886. "packing_fee"=>$info["pakge_fee"],
  887. "mark_fee"=>$info["mark_fee"],
  888. "nake_fee"=>$info["nake_fee"],
  889. "cert_fee"=>$info["cert_fee"],
  890. "cost_fee"=>$info["cost_fee"],
  891. "num"=>$bidinfo["num"],
  892. ];
  893. if($info['is_gold_price']==1){
  894. $price = GoldPrice($god, $budget/100);
  895. $info['sale_price'] =round($price,2);
  896. }
  897. $info['specinfo'] = json_decode($info['specinfo'],true);
  898. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  899. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  900. $info['bargain'] =$bargain;
  901. return app_show(0,"获取成功",$info);
  902. }
  903. public function feededit(){
  904. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  905. if($bidNo==""){
  906. return error_show(1002,"参数bidNo不能为空");
  907. }
  908. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  909. if($bidinfo==false){
  910. return error_show(1003,"未找到信息数据");
  911. }
  912. if($bidinfo['status']>=5){
  913. return error_show(1004,"咨询单已确认无法修改");
  914. }
  915. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  916. if($zxinfo==false){
  917. return error_show(1003,"未找到信息数据");
  918. }
  919. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  920. if($zx==false){
  921. return error_show(1003,"未找咨询信息数据");
  922. }
  923. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  924. if($pname==""){
  925. return error_show(1002,"参数pname不能为空");
  926. }
  927. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  928. // if($brandid==""){
  929. // return error_show(1002,"参数brandid不能为空");
  930. // }
  931. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  932. if($cat_id==""){
  933. return error_show(1002,"参数cat_id不能为空");
  934. }
  935. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  936. if($specin==""){
  937. return error_show(1003,"参数specinfo不能为空");
  938. }
  939. $specinfo=[];
  940. foreach ($specin as $v){
  941. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  942. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  943. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  944. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  945. $specinfo[]=$v;
  946. }
  947. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  948. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  949. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  950. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  951. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  952. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  953. :"";
  954. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  955. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  956. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  957. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  958. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  959. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  960. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  961. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  962. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  963. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  964. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  965. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  966. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  967. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  968. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  969. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  970. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  971. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  972. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  973. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  974. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  975. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  976. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  977. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  978. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  979. $cat_top_list = made($cat_id);
  980. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  981. if ($is_gold_price == 1 && $cat_top_id == 6) {
  982. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  983. ->find();
  984. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  985. $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;
  986. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  987. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  988. $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  989. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  990. $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"];
  991. }else{
  992. $saleprice = ($open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  993. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  994. }
  995. Db::startTrans();
  996. try{
  997. $data=[
  998. "good_name"=>$pname,
  999. "brand_id"=>$brandid,
  1000. "cat_id"=>$cat_id,
  1001. "specinfo"=>json_encode($specinfo),
  1002. // "material"=>$material,
  1003. "unit_id"=>$unit_id,
  1004. "cost_desc"=>$cost_desc,
  1005. "work_day"=>$work_day,
  1006. "delivery_day"=>$delivery_day,
  1007. "good_img"=>$good_img,
  1008. "expire_day"=>$expire_day,
  1009. "origin_place"=>$origin_place,
  1010. "supplierNo"=>$supplierNo,
  1011. "pay_way"=>$pay_way,
  1012. "tax"=>$tax,
  1013. "send_way"=>$send_way,
  1014. "metal_id"=>$metal_id,
  1015. "is_gold_price"=>$is_gold_price,
  1016. "config"=>$config,
  1017. "other_config"=>$other_config,
  1018. "weight"=>$weight,
  1019. "is_diff"=>$is_diff,
  1020. "demo_fee"=>$demo_fee,
  1021. "delivery_fee"=>$delivery_fee,
  1022. "open_fee"=>$open_fee,
  1023. "pakge_fee"=>$pakge_fee,
  1024. "nake_fee"=>$nake_fee,
  1025. "mark_fee"=>$mark_fee,
  1026. "cert_fee"=>$cert_fee,
  1027. "cost_fee"=>$cost_fee,
  1028. "sale_cost_fee"=>$sale_cost_fee,
  1029. "total_fee"=>$total_fee,
  1030. "sale_price"=>$saleprice,
  1031. "supply_area"=>$supply_area,
  1032. "remark"=>$remark,
  1033. "updatetime"=>date("Y-m-d H:i:s")
  1034. ];
  1035. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1036. if($insert){
  1037. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1038. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1039. if($projectinfo==false){
  1040. Db::rollback();
  1041. return error_show(1006,"未找到项目信息");
  1042. }
  1043. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1044. if($feed==false){
  1045. Db::rollback();
  1046. return error_show(1006,"未找到项目反馈信息");
  1047. }
  1048. $feed['good_name']=$pname;
  1049. $feed['good_type']=$projectinfo['good_type'];
  1050. $feed['cat_id']=$cat_id;
  1051. $feed['sale_price']=$saleprice;
  1052. $feed['origin_price']=$total_fee;
  1053. $feed['updatetime']=date("Y-m-d H:i:s");
  1054. $temp['updatetime']=date("Y-m-d H:i:s");
  1055. $nu = Db::name("project_feedback")->save($feed);
  1056. if($nu==false){
  1057. Db::rollback();
  1058. return error_show(1006,"项目反馈失败");
  1059. }else{
  1060. $old_projectinfo_status = $projectinfo['status'];
  1061. $projectinfo['status']=2;
  1062. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1063. $up = Db::name("project_info")->save($projectinfo);
  1064. if($up){
  1065. //修改状态,添加待办,只记录动作
  1066. ActionLog::logAdd($this->post['token'], [
  1067. "order_code" => $projectinfo['pgNo'],//编码
  1068. "status" => $old_projectinfo_status,//这里的status是之前的值
  1069. "action_remark" => '',//备注
  1070. "action_type" => "status"//新建create,编辑edit,更改状态status
  1071. ], "PRO", 2, $projectinfo);
  1072. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1073. if ($count == 0) {
  1074. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1075. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1076. if ($project_id) {
  1077. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1078. if ($proc == false) {
  1079. Db::rollback();
  1080. return error_show(1006, "项目反馈失败");
  1081. }else{
  1082. //修改状态,添加待办
  1083. ActionLog::logAdd($this->post['token'], [
  1084. "order_code" => $projectinfo['projectNo'],//项目编码
  1085. "status" => 1,//这里的status是之前的值
  1086. "action_remark" => '',//备注
  1087. "action_type" => "status"//新建create,编辑edit,更改状态status
  1088. ], "PRO", 2, $this->post);
  1089. ProcessOrder::AddProcess($this->post['token'], [
  1090. "order_type" => 'PRO',
  1091. "order_code" => $projectinfo['projectNo'],
  1092. "order_id" => $project_id,
  1093. "order_status" => 2
  1094. ]);
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. }
  1101. Db::commit();
  1102. return app_show(0,"编辑成功");
  1103. }else{
  1104. Db::rollback();
  1105. return error_show(1004,"编辑失败");
  1106. }
  1107. }catch (\Exception $e){
  1108. Db::rollback();
  1109. return error_show(1004,$e->getMessage());
  1110. }
  1111. }
  1112. public function bargain_add(){
  1113. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1114. if($bidNo===""){
  1115. return error_show(1004,"参数bidNo不能为空");
  1116. }
  1117. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1118. if($info==false){
  1119. return error_show(1004,"未找到商品数据");
  1120. }
  1121. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1122. if($consult==false){
  1123. return error_show(1004,"未找到咨询数据");
  1124. }
  1125. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1126. if($bargain_price===""){
  1127. return error_show(1004,"参数bargain_price不能为空");
  1128. }
  1129. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1130. if($info['is_gold_price']==1){
  1131. if($cost_price==""){
  1132. return error_show(1004,"参数cost_price不能为空");
  1133. }
  1134. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1135. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1136. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1137. ->find();
  1138. $bargain_price = ($info['open_fee'] / $consult['num'] + $info['weight'] * $gold["price"] + $cost_price *$info['weight'] +
  1139. $info['pakge_fee'] + $info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1140. }
  1141. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1142. // if($bargain_reason===""){
  1143. // return error_show(1004,"参数bargain_reason不能为空");
  1144. // }
  1145. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1146. if($infos==false){
  1147. return error_show(1004,"未找到商品数据");
  1148. }
  1149. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1150. return error_show(1004,"咨询单招标未结束或已确认商品");
  1151. }
  1152. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1153. if($token==''){
  1154. return error_show(105,"参数token不能为空");
  1155. }
  1156. $user =GetUserInfo($token);
  1157. if(empty($user)||$user['code']!=0){
  1158. return error_show(1002,"用户数据不存在");
  1159. }
  1160. //新增两个字段
  1161. //议价备注
  1162. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1163. //议价原因id
  1164. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1165. if ($result_info_id != '') {
  1166. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1167. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1168. }
  1169. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1170. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1171. $bargainNo =makeNo("BA");
  1172. Db::startTrans();//::todo 金价 毛利计算
  1173. try{
  1174. $data=[
  1175. "bidsNo"=>$bidNo,
  1176. "infoNo"=>$info['infoNo'],
  1177. "zxNo"=>$info['zxNo'],
  1178. "bargainNo"=>$bargainNo,
  1179. "bargain_type"=>1,
  1180. "bargain_reason"=>$bargain_reason,
  1181. "sale_price"=>$info['sale_price'],
  1182. "cost_before_price"=>$info['cost_fee'],
  1183. "cost_after_price"=>$cost_price,
  1184. "before_rate"=>round(($info['sale_price']-$info['total_fee'])/$info['sale_price'],2),
  1185. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1186. "after_price"=>$bargain_price,
  1187. "exam_info"=>"",
  1188. "status"=>0,
  1189. "is_del"=>0,
  1190. "creater"=>$creater,
  1191. "createrid"=>$createrid,
  1192. "addtime"=>date("Y-m-d H:i:s"),
  1193. "updatetime"=>date("Y-m-d H:i:s"),
  1194. 'bargain_remark'=>$bargain_remark,
  1195. 'result_info_id'=>$result_info_id,
  1196. ];
  1197. $int = Db::name("bargain_order")->insert($data);
  1198. if($int){
  1199. $info['status']=3;
  1200. $info['updatetime']=date("Y-m-d H:i:s");
  1201. $up =Db::name("consult_bids")->save($info);
  1202. if($up){
  1203. $old_infos_status = $infos['status'];
  1204. $infos['status']=3;
  1205. $infos['updatetime']=date("Y-m-d H:i:s");
  1206. $ups =Db::name("consult_info")->save($infos);
  1207. if($ups){
  1208. //修改状态,添加待办
  1209. ActionLog::logAdd($this->post['token'], [
  1210. "order_code" => $infos['infoNo'],//咨询单详情编号
  1211. "status" => $old_infos_status,//这里的status是之前的值
  1212. "action_remark" => '',//备注
  1213. "action_type" => "status"//新建create,编辑edit,更改状态status
  1214. ], "ZXD", $infos['status'], $infos);
  1215. ProcessOrder::AddProcess($this->post['token'], [
  1216. "order_type" => 'ZXD',
  1217. "order_code" => $infos['infoNo'],//咨询单详情编号
  1218. "order_id" => $infos['id'],
  1219. "order_status" => $infos['status']
  1220. ]);
  1221. Db::commit();
  1222. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1223. }
  1224. }
  1225. }
  1226. Db::rollback();
  1227. return error_show(1004,"议价单新建失败");
  1228. }catch (\Exception $e){
  1229. Db::rollback();
  1230. return error_show(1004,$e->getMessage());
  1231. }
  1232. }
  1233. //选择商品
  1234. public function bids_check(){
  1235. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1236. if($bidNo===""){
  1237. return error_show(1004,"参数bidNo不能为空");
  1238. }
  1239. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1240. if($info==false){
  1241. return error_show(1004,"未找到商品数据");
  1242. }
  1243. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1244. if($infos==false){
  1245. return error_show(1004,"未找到商品数据");
  1246. }
  1247. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1248. return error_show(1004,"咨询单招标未结束或已确认商品");
  1249. }
  1250. Db::startTrans();
  1251. try {
  1252. $info['status']=6;
  1253. $info['updatetime']=date("Y-m-d H:i:s");
  1254. $bids = Db::name("consult_bids")->save($info);
  1255. if($bids){
  1256. $old_infos_status = $infos['status'];
  1257. $infos['status']=4;
  1258. $infos['updatetime']=date("Y-m-d H:i:s");
  1259. $se = Db::name("consult_info")->save($infos);
  1260. if($se){
  1261. //修改状态,添加待办
  1262. ActionLog::logAdd($this->post['token'], [
  1263. "order_code" => $infos['infoNo'],//咨询单详情编号
  1264. "status" => $old_infos_status,//这里的status是之前的值
  1265. "action_remark" => '',//备注
  1266. "action_type" => "status"//新建create,编辑edit,更改状态status
  1267. ], "ZXD", $infos['status'], $infos);
  1268. ProcessOrder::AddProcess($this->post['token'], [
  1269. "order_type" => 'ZXD',
  1270. "order_code" => $infos['infoNo'],//咨询单详情编号
  1271. "order_id" => $infos['id'],
  1272. "order_status" => $infos['status']
  1273. ]);
  1274. Db::commit();
  1275. return app_show(0,"商品确定成功");
  1276. }
  1277. }
  1278. Db::rollback();
  1279. return error_show(1004,"商品确认失败");
  1280. }catch (\Exception $e){
  1281. Db::rollback();
  1282. return error_show(1004,$e->getMessage());
  1283. }
  1284. }
  1285. //议价审核
  1286. /**
  1287. * status:
  1288. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1289. */
  1290. public function bargain_status(){
  1291. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1292. if($bargainNo===""){
  1293. return error_show(1004,"参数bargainNo不能为空");
  1294. }
  1295. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1296. if($info==false){
  1297. return error_show(1004,"未找到议价数据");
  1298. }
  1299. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1300. if($bids==false){
  1301. return error_show(1004,"未找到商品数据");
  1302. }
  1303. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1304. if($coninfo==false){
  1305. return error_show(1004,"未找到咨询单数据");
  1306. }
  1307. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1308. if($status===''){
  1309. return error_show(1005,"参数status不能为空");
  1310. }
  1311. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1312. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1313. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1314. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1315. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1316. if($bids['is_gold_price']==1){
  1317. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1318. ->find();
  1319. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1320. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1321. $saleprice = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] + $bids['cost_fee']*$bids['weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $budget);
  1322. $rate_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] +$bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $rate);
  1323. $money_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] +$bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $money_rate);
  1324. $lower_price = ($bids['open_fee'] / $coninfo['num'] + $bids['weight']* $gold["price"] +$bids['cost_fee']*$bids['weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee']) / (1 - $lower_rate);
  1325. }else{
  1326. if($bids['nake_fee']!=0){
  1327. $saleprice = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'])/ (1 - $budget);
  1328. $rate_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'])/ (1 - $rate);
  1329. $money_price =($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'])/ (1 - $money_rate);
  1330. $lower_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee']) / (1 - $lower_rate);
  1331. }else{
  1332. $saleprice = ($bids['open_fee']/$coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee']) / (1 - $budget);
  1333. $rate_price =($bids['open_fee'] /$coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'])/ (1 - $rate);
  1334. $money_price =($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee']) / (1 - $money_rate);
  1335. $lower_price = ($bids['open_fee'] / $coninfo['num']+$bids['cost_fee']*$bids['weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'])/ (1 - $lower_rate);
  1336. }
  1337. }
  1338. if($status==1){
  1339. if($info['status']==0){
  1340. if($info['after_price']<$rate_price){
  1341. $info['status']=2;
  1342. }else{
  1343. $info['status']=1;
  1344. }
  1345. }elseif($info['status']==2){
  1346. $info['status']=4;
  1347. }elseif($info['status']==4||$info['status']==5){
  1348. if($info['after_price']<$money_price){
  1349. $info['status']=7;
  1350. }else{
  1351. $info['status']=6;
  1352. }
  1353. }elseif($info['status']==7){
  1354. $info['lower_price'] =$lower_price;
  1355. if($info['after_price']<$lower_price){
  1356. $info['status']=10;
  1357. }else{
  1358. $info['status']=9;
  1359. }
  1360. }
  1361. }else{
  1362. if($info['status']==0){
  1363. $info['status']=3;
  1364. }elseif($info['status']==2){
  1365. $info['status']=5;
  1366. }elseif($info['status']==4||$info['status']==5){
  1367. $info['status']=8;
  1368. }elseif($info['status']==7){
  1369. $info['lower_price'] =$lower_price;
  1370. $info['status']=11;
  1371. }
  1372. }
  1373. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1374. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1375. if($token==''){
  1376. return error_show(105,"参数token不能为空");
  1377. }
  1378. $user =GetUserInfo($token);
  1379. if(empty($user)||$user['code']!=0){
  1380. return error_show(1002,"用户数据不存在");
  1381. }
  1382. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1383. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1384. Db::startTrans();
  1385. try{
  1386. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1387. $examinfo[]=["status"=>$info['status'],"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1388. // $info['status'] =$status;
  1389. $info['remark'] =$remark;
  1390. $info['exam_info']=json_encode($examinfo) ;
  1391. $info['updatetime'] =date("Y-m-d H:i:s");
  1392. $up =Db::name("bargain_order")->save($info);
  1393. if($up){
  1394. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1395. $bids['status']=5;
  1396. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1397. $bids['sale_price']=$info['after_price'];
  1398. if($bids['is_gold_price']==1){
  1399. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1400. // ->find();
  1401. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1402. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1403. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1404. }
  1405. }
  1406. $bids['updatetime']=date("Y-m-d H:i:s");
  1407. $up =Db::name("consult_bids")->save($bids);
  1408. if($up==false){
  1409. Db::rollback();
  1410. return error_show(1004,"数据更新失败");
  1411. }
  1412. }
  1413. Db::commit();
  1414. return app_show(0,"更新成功");
  1415. }
  1416. }catch (\Exception $e){
  1417. Db::rollback();
  1418. return error_show(1004,$e->getMessage());
  1419. }
  1420. }
  1421. public function bargain_info(){
  1422. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1423. if($bargainNo===""){
  1424. return error_show(1004,"参数bargainNo不能为空");
  1425. }
  1426. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1427. if($info==false){
  1428. return error_show(1004,"未找到议价数据");
  1429. }
  1430. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1431. if($bidinfos==false){
  1432. return error_show(1004,"未找到商品数据");
  1433. }
  1434. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1435. ->find();
  1436. if($consultinfos==false){
  1437. return error_show(1004,"未找到咨询商品数据");
  1438. }
  1439. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1440. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1441. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1442. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1443. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1444. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1445. if($bidinfos['brand_id']!=0){
  1446. $info['brand_id'] = $bidinfos['brand_id'];
  1447. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1448. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1449. }else{
  1450. $info["brand_name"]="";
  1451. $info["brand_id"]="";
  1452. }
  1453. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1454. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1455. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1456. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1457. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1458. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1459. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1460. $info['budget'] =$budget;
  1461. $god=[
  1462. "metal_id"=>$bidinfos['metal_id'],
  1463. "weight"=>$bidinfos["weight"],
  1464. "demo_fee"=>$bidinfos["demo_fee"],
  1465. "delivery_fee"=>$bidinfos["delivery_fee"],
  1466. "open_fee"=>$bidinfos["open_fee"],
  1467. "packing_fee"=>$bidinfos["pakge_fee"],
  1468. "mark_fee"=>$bidinfos["mark_fee"],
  1469. "nake_fee"=>$bidinfos["nake_fee"],
  1470. "cert_fee"=>$bidinfos["cert_fee"],
  1471. "cost_fee"=>$bidinfos["cost_fee"],
  1472. "num"=>$bidinfoe["num"],
  1473. ];
  1474. $info['gold_price']=0;
  1475. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1476. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1477. ->find();
  1478. $info['gold_price'] =$gold['price'];
  1479. $lower_price = ($bidinfos['open_fee'] / $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);
  1480. }else{
  1481. if($bidinfos['nake_fee']!=0){
  1482. $lower_price =($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);
  1483. }else{
  1484. $lower_price = ($bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1485. }
  1486. }
  1487. $info['cost_desc'] =$bidinfos['cost_desc'];
  1488. $info['work_day'] =$bidinfos['work_day'];
  1489. $info['delivery_day'] =$bidinfos['delivery_day'];
  1490. $info['expire_day'] =$bidinfos['expire_day'];
  1491. $info['origin_place'] =$bidinfos['origin_place'];
  1492. $info['origin_addr'] ="";
  1493. if($bidinfos['origin_place']!=''){
  1494. $code = explode(",",$bidinfos['origin_place']);
  1495. $temp=[];
  1496. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1497. $temp['city_code']=isset($code[1])?$code[1]:"";
  1498. $temp['area_code']=isset($code[2])?$code[2]:"";
  1499. $addr= GetAddr(json_encode($temp));
  1500. $info['origin_addr'] = $addr;
  1501. }
  1502. $info['supplierNo'] =$bidinfos['supplierNo'];
  1503. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1504. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1505. $info['pay_way'] =$bidinfos['pay_way'];
  1506. $info['tax'] =$bidinfos['tax'];
  1507. $info['send_way'] =$bidinfos['send_way'];
  1508. $info['metal_id'] =$bidinfos['metal_id'];
  1509. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1510. $info['config'] =$bidinfos['config'];
  1511. $info['other_config'] =$bidinfos['other_config'];
  1512. $info['weight'] =$bidinfos['weight'];
  1513. $info['is_diff'] =$bidinfos['is_diff'];
  1514. $info['demo_fee'] =$bidinfos['demo_fee'];
  1515. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1516. $info['open_fee'] =$bidinfos['open_fee'];
  1517. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1518. $info['nake_fee'] =$bidinfos['nake_fee'];
  1519. $info['mark_fee'] =$bidinfos['mark_fee'];
  1520. $info['cert_fee'] =$bidinfos['cert_fee'];
  1521. $info['cost_fee'] =$bidinfos['cost_fee'];
  1522. $info['total_fee'] =$bidinfos['total_fee'];
  1523. $info['supply_area'] =$bidinfos['supply_area'];
  1524. $info['remark'] =$bidinfos['remark'];
  1525. $info['is_addrs'] =$consultinfos['is_addrs'];
  1526. $info['is_custom'] =$consultinfos['is_custom'];
  1527. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1528. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1529. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1530. if($info['status']==7){
  1531. $info['lower_price'] =$lower_price;
  1532. }
  1533. //获取议价原因
  1534. if ($info['result_info_id'] != 0) {
  1535. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1536. } else {
  1537. $info['result_info'] = '';
  1538. }
  1539. return app_show(0,"获取成功",$info);
  1540. }
  1541. public function bidlist(){
  1542. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1543. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1544. $where=[['is_del',"=",0]];
  1545. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1546. if ($zxNo !== "") {
  1547. $where[] = ['zxNo','=',$zxNo];
  1548. }
  1549. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1550. if ($infoNo !== "") {
  1551. $where[] = ['infoNo','=',$infoNo];
  1552. }
  1553. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1554. if ($bidNo !== "") {
  1555. $where[] = ['bidNo','=',$bidNo];
  1556. }
  1557. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1558. if ($pgNo !== "") {
  1559. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1560. $where[] = ['infoNo','in',$bidinfo];
  1561. }
  1562. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1563. if ($bargain_status !== "") {
  1564. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1565. $where[] = ['infoNo','in',$bidinfo];
  1566. }
  1567. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1568. if ($projectNo !== "") {
  1569. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1570. ("zxNo");
  1571. $where[] = ['zxNo','in',$zxlist];
  1572. }
  1573. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1574. if($is_own==1){
  1575. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1576. if($token==""){
  1577. return error_show(101,'token不能为空');
  1578. }
  1579. $apply_id =GetUserInfo($token);
  1580. if(empty($apply_id)||$apply_id['code']!=0){
  1581. return error_show(1002,"申请人数据不存在");
  1582. }
  1583. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1584. $where[]=['createrid',"=",$rm];
  1585. }
  1586. $count = Db::name('consult_bids')->where($where)->count();
  1587. $total = ceil($count / $size);
  1588. $page = $page >= $total ? $total : $page;
  1589. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1590. $data=[];
  1591. foreach ($list as $value){
  1592. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1593. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1594. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1595. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1596. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1597. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1598. if($value['brand_id']!=0){
  1599. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1600. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1601. }else{
  1602. $value["brand_name"]="";
  1603. $value["brand_id"]="";
  1604. }
  1605. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1606. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1607. $god=[
  1608. "metal_id"=>$value['metal_id'],
  1609. "weight"=>$value["weight"],
  1610. "demo_fee"=>$value["demo_fee"],
  1611. "delivery_fee"=>$value["delivery_fee"],
  1612. "open_fee"=>$value["open_fee"],
  1613. "packing_fee"=>$value["pakge_fee"],
  1614. "mark_fee"=>$value["mark_fee"],
  1615. "nake_fee"=>$value["nake_fee"],
  1616. "cert_fee"=>$value["cert_fee"],
  1617. "cost_fee"=>$value["cost_fee"],
  1618. "num"=>$bidinfo["num"],
  1619. ];
  1620. if($value['is_gold_price']==1){
  1621. $price = GoldPrice($god, $budget/100);
  1622. $value['sale_price'] = round($price,2);
  1623. }
  1624. $value['specinfo'] = json_decode($value['specinfo'],true);
  1625. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1626. $value['bargain_status']=$bidinfo['bargain_status'];
  1627. //reject驳回原因,status==5表示驳回
  1628. $value['reject']=[];
  1629. if ($value['status'] == 5) {
  1630. $value['reject'] = Db::name('bargain_order')
  1631. ->field('id,remark,status')
  1632. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1633. ->whereIn('status', [5, 6])
  1634. ->find();
  1635. }
  1636. //产地
  1637. if($value['origin_place']!=''){
  1638. $code = explode(",",$value['origin_place']);
  1639. $temp=[];
  1640. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1641. $temp['city_code']=isset($code[1])?$code[1]:"";
  1642. $temp['area_code']=isset($code[2])?$code[2]:"";
  1643. $addr= GetAddr(json_encode($temp));
  1644. $value['origin_addr'] = $addr;
  1645. }
  1646. $data[] = $value;
  1647. }
  1648. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1649. }
  1650. public function feedlist(){
  1651. $where=[['is_del',"=",0]];
  1652. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1653. if ($zxNo !== "") {
  1654. $where[] = ['zxNo','=',$zxNo];
  1655. }
  1656. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1657. if ($infoNo !== "") {
  1658. $where[] = ['infoNo','=',$infoNo];
  1659. }
  1660. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1661. if ($bidNo !== "") {
  1662. $where[] = ['bidNo','=',$bidNo];
  1663. }
  1664. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1665. if ($projectNo !== "") {
  1666. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1667. ("zxNo");
  1668. $where[] = ['zxNo','in',$zxlist];
  1669. }
  1670. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1671. if($token==''){
  1672. return error_show(102,"参数token不能为空");
  1673. }
  1674. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1675. if($is_own==1){
  1676. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1677. if($token==""){
  1678. return error_show(101,'token不能为空');
  1679. }
  1680. $apply_id =GetUserInfo($token);
  1681. if(empty($apply_id)||$apply_id['code']!=0){
  1682. return error_show(1002,"申请人数据不存在");
  1683. }
  1684. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1685. $where[]=['createrid',"=",$rm];
  1686. }
  1687. $list =Db::name('consult_bids')->where($where)->select();
  1688. $data=[];
  1689. foreach ($list as $value){
  1690. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1691. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1692. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1693. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1694. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1695. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1696. if($value['brand_id']!=0){
  1697. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1698. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1699. }else{
  1700. $value["brand_name"]="";
  1701. $value["brand_id"]="";
  1702. }
  1703. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1704. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1705. $god=[
  1706. "metal_id"=>$value['metal_id'],
  1707. "weight"=>$value["weight"],
  1708. "demo_fee"=>$value["demo_fee"],
  1709. "delivery_fee"=>$value["delivery_fee"],
  1710. "open_fee"=>$value["open_fee"],
  1711. "packing_fee"=>$value["pakge_fee"],
  1712. "mark_fee"=>$value["mark_fee"],
  1713. "nake_fee"=>$value["nake_fee"],
  1714. "cert_fee"=>$value["cert_fee"],
  1715. "cost_fee"=>$value["cost_fee"],
  1716. "num"=>$bidinfo["num"],
  1717. ];
  1718. if($value['is_gold_price']==1){
  1719. $price = GoldPrice($god, $budget/100);
  1720. $value['sale_price'] =round($price,2);
  1721. }
  1722. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1723. $value['specinfo'] = json_decode($value['specinfo'],true);
  1724. $value['bargain_status']=$bidinfo['bargain_status'];
  1725. $data[]=$value;
  1726. }
  1727. return app_show(0,"获取成功",$data);
  1728. }
  1729. public function bragain_list(){
  1730. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1731. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1732. $where=[['is_del',"=",0]];
  1733. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1734. if($bidsNo!=""){
  1735. $where[]=["bidsNo","=",$bidsNo];
  1736. }
  1737. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1738. if ($zxNo !== "") {
  1739. $where[] = ['zxNo','=',$zxNo];
  1740. }
  1741. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1742. if ($infoNo !== "") {
  1743. $where[] = ['infoNo','=',$infoNo];
  1744. }
  1745. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1746. if ($projectNo !== "") {
  1747. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1748. ("zxNo");
  1749. $where[] = ['zxNo','in',$zxlist];
  1750. }
  1751. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1752. if ($pgNo !== "") {
  1753. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1754. $where[] = ['infoNo','in',$bidinfo];
  1755. }
  1756. $count=Db::name("bargain_order")->where($where)->count();
  1757. $total = ceil($count / $size);
  1758. $page = $page >= $total ? $total : $page;
  1759. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1760. $data=[];
  1761. foreach ($list as $value){
  1762. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1763. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1764. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1765. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1766. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1767. if($bidinfos['brand_id']!=0){
  1768. $value['brand_id'] = $bidinfos['brand_id'];
  1769. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1770. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1771. }else{
  1772. $value["brand_name"]="";
  1773. $value["brand_id"]="";
  1774. }
  1775. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1776. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1777. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1778. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1779. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1780. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1781. $value['budget'] =$budget;
  1782. $god=[
  1783. "metal_id"=>$bidinfos['metal_id'],
  1784. "weight"=>$bidinfos["weight"],
  1785. "demo_fee"=>$bidinfos["demo_fee"],
  1786. "delivery_fee"=>$bidinfos["delivery_fee"],
  1787. "open_fee"=>$bidinfos["open_fee"],
  1788. "packing_fee"=>$bidinfos["pakge_fee"],
  1789. "mark_fee"=>$bidinfos["mark_fee"],
  1790. "nake_fee"=>$bidinfos["nake_fee"],
  1791. "cert_fee"=>$bidinfos["cert_fee"],
  1792. "cost_fee"=>$bidinfos["cost_fee"],
  1793. "num"=>$bidinfoe["num"],
  1794. ];
  1795. // if($bidinfos['is_gold_price']==1){
  1796. // $price = GoldPrice($god, $budget/100);
  1797. // }else{
  1798. // $price = GoodPrice($god, $budget/100);
  1799. // }
  1800. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1801. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1802. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1803. $data[]=$value;
  1804. }
  1805. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1806. }
  1807. public function crontablist(){
  1808. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1809. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1810. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1811. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1812. if ($zxNo !== "") {
  1813. $where[] = ['a.zxNo','=',$zxNo];
  1814. }
  1815. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1816. if ($salesman !== "") {
  1817. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1818. $where[]= ["b.salesman",'like',"%$salesman%"];
  1819. }
  1820. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1821. if ($cpName !== "") {
  1822. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1823. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1824. }
  1825. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1826. if ($khNo !== "") {
  1827. // $where['khNo'] = $khNo;
  1828. $where[]= ["b.khNo",'like',"%$khNo%"];
  1829. }
  1830. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1831. if ($start !="") {
  1832. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1833. $where[]= ["a.addtime",'>=',$start];
  1834. }
  1835. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1836. if($end !=""){
  1837. $where[]= ["a.addtime",'<=',$end];
  1838. }
  1839. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1840. if ($status !== "") {
  1841. $where[]= ["a.status",'=',$status];
  1842. }
  1843. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1844. ->count();
  1845. $total = ceil($count / $size);
  1846. $page = $page >= $total ? $total : $page;
  1847. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1848. ->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();
  1849. $data=[];
  1850. foreach ($list as $value){
  1851. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1852. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1853. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1854. $value['khname']="";
  1855. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1856. true):[];
  1857. if($value['khNo']!==""){
  1858. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1859. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1860. }
  1861. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1862. $data[]=$value;
  1863. }
  1864. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1865. }
  1866. }