Consult.php 96 KB

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